PDA

View Full Version : List files on ftp server using QNetworkAccessManager



blackbubblegum
20th February 2012, 07:07
Hi,

I need to get a list of files from a ftp server and as Qt-Doc recommended wanted to use the QNetworkAccessManager for that. But I have no clue where to start. With QFtp everything is so easy :).

My code to connect isbasically this:


QNetworkAccessManager* qnam = new QNetworkAccessManager(this);
QUrl url = QUrl();
url.setHost(QString("host"));
url.setUserName(QString("user"));
url.setPassword(QString("pswd"));
url.setPort(21);
QNetworkRequest nRequest(url);
this->qnam->get(nRequest);

But the ftp server log doesn't show any response to this. Which it did, when I tried QFtp.

Is there somewhere a nice tutorial for QNam or even good sample code for this?

Thanks for your help,
bbg

ChrisW67
20th February 2012, 07:28
Your code is going to fail because you haven't provided a URL to access, e.g.:


QUrl url("ftp://my.server.com/somefile.txt");


The QNetworkAccessManager support for FTP extends to get and put requests only, so you should use QFtp if you are doing more with your FTP server.

blackbubblegum
20th February 2012, 10:39
That answers my questions. Thanks :).