How can i get ftp files show on my list widget using QNetworkAccessManager Qt 5.8?
-
@walter-j You should connect a slot to http://doc.qt.io/qt-4.8/qftp.html#stateChanged and see what happens
-
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.
-
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; }
-
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 :)
-
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.
-
Where did you download it from ?
-
here : https://github.com/qt/qthttp
-
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 -