Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can i get ftp files show on my list widget using QNetworkAccessManager Qt 5.8?
QtWS25 Last Chance

How can i get ftp files show on my list widget using QNetworkAccessManager Qt 5.8?

Scheduled Pinned Locked Moved Solved General and Desktop
41 Posts 7 Posters 13.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    walter-j
    wrote on 9 Feb 2017, 22:32 last edited by
    #11

    please be patient with me im new in Qt. i have typed git clone git://code.qt.io/qt/qtftp.git. i have this message checking connectivity....done. what can i do else?

    Josephat Kabitshwa

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Feb 2017, 22:37 last edited by
      #12

      This has nothing to do with Qt.

      Didn't you get a new folder named qtftp ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        walter-j
        wrote on 9 Feb 2017, 22:38 last edited by
        #13

        yes . will i build it in Qt?

        Josephat Kabitshwa

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Feb 2017, 22:45 last edited by
          #14

          Open the project .pro file with Qt Creator and build it.

          By the way, what OS are you on ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • W Offline
            W Offline
            walter-j
            wrote on 9 Feb 2017, 22:48 last edited by
            #15

            linux mint 18 sarah

            Josephat Kabitshwa

            1 Reply Last reply
            0
            • W Offline
              W Offline
              walter-j
              wrote on 9 Feb 2017, 22:53 last edited by
              #16

              i got this message : cannot create a directory / mkspecs/modules-inst when im building it

              Josephat Kabitshwa

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 9 Feb 2017, 22:55 last edited by
                #17

                Which version of Qt are you using to build that module ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  walter-j
                  wrote on 9 Feb 2017, 22:59 last edited by
                  #18

                  Qt 5.7.1 . now i can build . what can i do else?

                  Josephat Kabitshwa

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    walter-j
                    wrote on 9 Feb 2017, 23:04 last edited by
                    #19

                    my programm does not recognize QFtp but i have already built it

                    Josephat Kabitshwa

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 9 Feb 2017, 23:18 last edited by
                      #20

                      Did you install the module ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      V 1 Reply Last reply 24 Feb 2017, 03:09
                      0
                      • W Offline
                        W Offline
                        walter-j
                        wrote on 9 Feb 2017, 23:18 last edited by
                        #21

                        yes i have installed the module

                        Josephat Kabitshwa

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 9 Feb 2017, 23:37 last edited by SGaist 2 Sept 2017, 23:38
                          #22

                          Did you add QT += ftp to your .pro file and re-run qmake after that ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • W Offline
                            W Offline
                            walter-j
                            wrote on 10 Feb 2017, 06:43 last edited by
                            #23

                            yes.

                            But commandFinshed signal does not work. here is my code:

                            FtpDialog.h

                            #ifndef FTPDIALOG_H
                            #define FTPDIALOG_H

                            #include <QDialog>
                            #include <QFtp>
                            #include <QMessageBox>
                            #include <QDebug>

                            namespace Ui {
                            class FtpDialog;
                            }

                            class FtpDialog : public QDialog
                            {
                            Q_OBJECT

                            public:
                            explicit FtpDialog(QWidget *parent = 0);
                            ~FtpDialog();

                            public slots:
                            void connectClicked();
                            void ftpFinished(int, bool);
                            void getFileList();
                            signals:

                            private:
                            Ui::FtpDialog *ui;
                            QFtp ftp;
                            };

                            #endif // FTPDIALOG_H

                            Josephat Kabitshwa

                            J 1 Reply Last reply 10 Feb 2017, 07:41
                            0
                            • W Offline
                              W Offline
                              walter-j
                              wrote on 10 Feb 2017, 06:48 last edited by
                              #24

                              FtpDialog.cpp

                              #include "ftpdialog.h"
                              #include "ui_ftpdialog.h"

                              FtpDialog::FtpDialog(QWidget *parent) :
                              QDialog(parent),
                              ui(new Ui::FtpDialog)
                              {
                              ui->setupUi(this);
                              connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectClicked()));
                              connect(&ftp,SIGNAL(commandFinished(int,bool)), this, SLOT(ftpFinished(int,bool)));

                              ui->disconnectButton->setEnabled(false);
                              ui->cdButton->setEnabled(false);
                              ui->upButton->setEnabled(false);
                              ui->getButton->setEnabled(false);
                              

                              }

                              FtpDialog::~FtpDialog()
                              {
                              delete ui;
                              }

                              void FtpDialog::connectClicked()
                              {
                              ui->connectButton->setEnabled(false);

                               ftp.connectToHost("ftp.trolltech.com");
                               ui->statusLabel->setText(tr("Connecting to host..."));
                              

                              }

                              void FtpDialog::ftpFinished(int request, bool error)
                              {
                              // Handle errors depending on the command caussing it
                              qDebug()<<ftp.currentCommand();
                              if(error)
                              {
                              switch(ftp.currentCommand())
                              {
                              case QFtp::ConnectToHost:
                              QMessageBox::warning(this, tr("Error"), tr("Failed to connect to host."));
                              ui->connectButton->setEnabled(true);

                                      break;
                                  case QFtp::Login:
                                      QMessageBox::warning(this, tr("Error"), tr("Failed to login."));
                                      ui->connectButton->setEnabled(true);
                              
                                      break;
                              
                                  case QFtp::List:
                                      QMessageBox::warning(this, tr("Error"),
                                                           tr("Failed to get file list.\nClosing connection"));
                                      ftp.close();
                              
                                      break;
                              
                                  }
                              
                                  ui->statusLabel->setText(tr("Ready."));
                              

                              }
                              // React to the current command and issue
                              // more commands or update the user interface
                              else
                              {
                              switch(ftp.currentCommand())
                              {
                              case QFtp::ConnectToHost:
                              ftp.login();

                                      break;
                                  case QFtp::Login:
                                      getFileList();
                              
                                      break;
                              
                                  case QFtp::Close:
                                      ui->connectButton->setEnabled(true);
                                     // getFileList();
                              
                                      break;
                                  case QFtp::List:
                                      ui->disconnectButton->setEnabled(true);
                                      ui->upButton->setEnabled(true);
                                      ui->statusLabel->setText(tr("Ready."));
                              
                                      break;
                              
                                  }
                              }
                              

                              }

                              void FtpDialog::getFileList()
                              {

                              }

                              Josephat Kabitshwa

                              J.HilkJ 1 Reply Last reply 10 Feb 2017, 07:47
                              0
                              • W walter-j
                                10 Feb 2017, 06:43

                                yes.

                                But commandFinshed signal does not work. here is my code:

                                FtpDialog.h

                                #ifndef FTPDIALOG_H
                                #define FTPDIALOG_H

                                #include <QDialog>
                                #include <QFtp>
                                #include <QMessageBox>
                                #include <QDebug>

                                namespace Ui {
                                class FtpDialog;
                                }

                                class FtpDialog : public QDialog
                                {
                                Q_OBJECT

                                public:
                                explicit FtpDialog(QWidget *parent = 0);
                                ~FtpDialog();

                                public slots:
                                void connectClicked();
                                void ftpFinished(int, bool);
                                void getFileList();
                                signals:

                                private:
                                Ui::FtpDialog *ui;
                                QFtp ftp;
                                };

                                #endif // FTPDIALOG_H

                                J Offline
                                J Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on 10 Feb 2017, 07:41 last edited by
                                #25

                                @walter-j You should connect a slot to http://doc.qt.io/qt-4.8/qftp.html#stateChanged and see what happens

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                1
                                • W Offline
                                  W Offline
                                  walter-j
                                  wrote on 10 Feb 2017, 07:46 last edited by
                                  #26

                                  But in the book they used commandFinished(int, bool) signal.

                                  Josephat Kabitshwa

                                  J 1 Reply Last reply 10 Feb 2017, 08:19
                                  0
                                  • W walter-j
                                    10 Feb 2017, 06:48

                                    FtpDialog.cpp

                                    #include "ftpdialog.h"
                                    #include "ui_ftpdialog.h"

                                    FtpDialog::FtpDialog(QWidget *parent) :
                                    QDialog(parent),
                                    ui(new Ui::FtpDialog)
                                    {
                                    ui->setupUi(this);
                                    connect(ui->connectButton, SIGNAL(clicked()), this, SLOT(connectClicked()));
                                    connect(&ftp,SIGNAL(commandFinished(int,bool)), this, SLOT(ftpFinished(int,bool)));

                                    ui->disconnectButton->setEnabled(false);
                                    ui->cdButton->setEnabled(false);
                                    ui->upButton->setEnabled(false);
                                    ui->getButton->setEnabled(false);
                                    

                                    }

                                    FtpDialog::~FtpDialog()
                                    {
                                    delete ui;
                                    }

                                    void FtpDialog::connectClicked()
                                    {
                                    ui->connectButton->setEnabled(false);

                                     ftp.connectToHost("ftp.trolltech.com");
                                     ui->statusLabel->setText(tr("Connecting to host..."));
                                    

                                    }

                                    void FtpDialog::ftpFinished(int request, bool error)
                                    {
                                    // Handle errors depending on the command caussing it
                                    qDebug()<<ftp.currentCommand();
                                    if(error)
                                    {
                                    switch(ftp.currentCommand())
                                    {
                                    case QFtp::ConnectToHost:
                                    QMessageBox::warning(this, tr("Error"), tr("Failed to connect to host."));
                                    ui->connectButton->setEnabled(true);

                                            break;
                                        case QFtp::Login:
                                            QMessageBox::warning(this, tr("Error"), tr("Failed to login."));
                                            ui->connectButton->setEnabled(true);
                                    
                                            break;
                                    
                                        case QFtp::List:
                                            QMessageBox::warning(this, tr("Error"),
                                                                 tr("Failed to get file list.\nClosing connection"));
                                            ftp.close();
                                    
                                            break;
                                    
                                        }
                                    
                                        ui->statusLabel->setText(tr("Ready."));
                                    

                                    }
                                    // React to the current command and issue
                                    // more commands or update the user interface
                                    else
                                    {
                                    switch(ftp.currentCommand())
                                    {
                                    case QFtp::ConnectToHost:
                                    ftp.login();

                                            break;
                                        case QFtp::Login:
                                            getFileList();
                                    
                                            break;
                                    
                                        case QFtp::Close:
                                            ui->connectButton->setEnabled(true);
                                           // getFileList();
                                    
                                            break;
                                        case QFtp::List:
                                            ui->disconnectButton->setEnabled(true);
                                            ui->upButton->setEnabled(true);
                                            ui->statusLabel->setText(tr("Ready."));
                                    
                                            break;
                                    
                                        }
                                    }
                                    

                                    }

                                    void FtpDialog::getFileList()
                                    {

                                    }

                                    J.HilkJ Offline
                                    J.HilkJ Offline
                                    J.Hilk
                                    Moderators
                                    wrote on 10 Feb 2017, 07:47 last edited by
                                    #27

                                    @walter-j

                                    keep in mind that QFftp has not been updated for a very long time and therefore may not automatically support your target FTp-Servers protocolls.

                                    I run into this, when one of my old projects worked fine with the old FTP-Server but failed completely with the new one.


                                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                    Q: What's that?
                                    A: It's blue light.
                                    Q: What does it do?
                                    A: It turns blue.

                                    1 Reply Last reply
                                    0
                                    • W walter-j
                                      10 Feb 2017, 07:46

                                      But in the book they used commandFinished(int, bool) signal.

                                      J Offline
                                      J Offline
                                      jsulm
                                      Lifetime Qt Champion
                                      wrote on 10 Feb 2017, 08:19 last edited by
                                      #28

                                      @walter-j I did not say you should not use commandFinished, just add another slot to see whether you get any state changes.

                                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • VRoninV Offline
                                        VRoninV Offline
                                        VRonin
                                        wrote on 10 Feb 2017, 09:18 last edited by
                                        #29

                                        You need an external library and I don't feel to recommend QFtp as it's not maintained anymore. libCURL is probably the standard library in the C/C++ world (and probably beyond). You can use a cpp wrapper like curlpp if you don't like the aftertaste C leaves in your mouth.

                                        This example (source) will download the list of files from ftp://ftp.funet.fi/ and save it in a file called ftp-list

                                        #include <stdio.h>
                                         
                                        #include <curl/curl.h>
                                         
                                        static size_t
                                        write_response(void *ptr, size_t size, size_t nmemb, void *data)
                                        {
                                          FILE *writehere = (FILE *)data;
                                          return fwrite(ptr, size, nmemb, writehere);
                                        }
                                         
                                        #define FTPBODY "ftp-list"
                                        #define FTPHEADERS "ftp-responses"
                                         
                                        int main(void)
                                        {
                                          CURL *curl;
                                          CURLcode res;
                                          FILE *ftpfile;
                                          FILE *respfile;
                                         
                                          /* local file name to store the file as */ 
                                          ftpfile = fopen(FTPBODY, "wb"); /* b is binary, needed on win32 */ 
                                         
                                          /* local file name to store the FTP server's response lines in */ 
                                          respfile = fopen(FTPHEADERS, "wb"); /* b is binary, needed on win32 */ 
                                         
                                          curl = curl_easy_init();
                                          if(curl) {
                                            /* Get a file listing from sunet */ 
                                            curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.funet.fi/");
                                            curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftpfile);
                                            /* If you intend to use this on windows with a libcurl DLL, you must use
                                               CURLOPT_WRITEFUNCTION as well */ 
                                            curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_response);
                                            curl_easy_setopt(curl, CURLOPT_HEADERDATA, respfile);
                                            res = curl_easy_perform(curl);
                                            /* Check for errors */ 
                                            if(res != CURLE_OK)
                                              fprintf(stderr, "curl_easy_perform() failed: %s\n",
                                                      curl_easy_strerror(res));
                                         
                                            /* always cleanup */ 
                                            curl_easy_cleanup(curl);
                                          }
                                         
                                          fclose(ftpfile); /* close the local file */ 
                                          fclose(respfile); /* close the response file */ 
                                         
                                          return 0;
                                        }
                                        

                                        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                                        ~Napoleon Bonaparte

                                        On a crusade to banish setIndexWidget() from the holy land of Qt

                                        1 Reply Last reply
                                        3
                                        • W Offline
                                          W Offline
                                          walter-j
                                          wrote on 11 Feb 2017, 13:10 last edited by
                                          #30

                                          stateChanged solved the problem.

                                          Thank you guys

                                          JK

                                          Josephat Kabitshwa

                                          1 Reply Last reply
                                          0

                                          20/41

                                          9 Feb 2017, 23:18

                                          • Login

                                          • Login or register to search.
                                          20 out of 41
                                          • First post
                                            20/41
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved