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?
Forum Updated to NodeBB v4.3 + New Features

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 14.6k Views 1 Watching
  • 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on 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 last edited by
      #30

      stateChanged solved the problem.

      Thank you guys

      JK

      Josephat Kabitshwa

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #31

        You're welcome !

        Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

        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 last edited by
          #32

          i have searched for it . i didn't find

          Josephat Kabitshwa

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #33

            Do you mean the "Topic Tools" button ?

            There's one just under your original post or at the bottom of the page under the last post.

            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 last edited by
              #34

              how can i clone QHttp? can i have the link for the repository?

              Josephat Kabitshwa

              1 Reply Last reply
              0
              • W Offline
                W Offline
                walter-j
                wrote on last edited by
                #35

                when compiling QHttp i got this error : /home/walter-j/Documents/5.8/gcc_64/mkspecs/features/qt_module_headers.prf:153: error: Cannot write file /include/QtHttp/QtHttpDepends: Cannot create parent directory

                can someone help me?

                Josephat Kabitshwa

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #36

                  Where did you download it from ?

                  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 last edited by
                    #37

                    here : https://github.com/qt/qthttp

                    Josephat Kabitshwa

                    1 Reply Last reply
                    0
                    • W Offline
                      W Offline
                      walter-j
                      wrote on last edited by
                      #38

                      can someone help me to download the right package of QHttp?

                      Thank your for your support

                      JK

                      Josephat Kabitshwa

                      1 Reply Last reply
                      0
                      • VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on last edited by
                        #39

                        The correct repository for Qt Http is http://code.qt.io/cgit/qt/qthttp.git/
                        Again, this is unmaintained code that has been abandoned, my advise is to use an external library that can do the same things (and more) see links above

                        "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
                        2
                        • SGaistS SGaist

                          Did you install the module ?

                          V Offline
                          V Offline
                          victor wang
                          wrote on last edited by
                          #40

                          @SGaist
                          Sorry i don't know how to install the module after i compiled the qtftp

                          D 1 Reply Last reply
                          0
                          • V victor wang

                            @SGaist
                            Sorry i don't know how to install the module after i compiled the qtftp

                            D Offline
                            D Offline
                            Devopia53
                            wrote on last edited by
                            #41

                            @victor-wang

                            Build procedure:

                            • cd QtFtp

                            • <QTDIR>/bin/syncqt.pl -version 5.5.0

                            • qmake

                            • make

                            • make install

                            1 Reply Last reply
                            0

                            • Login

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