PDA

View Full Version : FTP function misbehaviour



kumarpraveen
8th July 2010, 05:09
In the below code i given a wrong ip address to connectToHost() function after that it don't show connection error :( please help me out.


#include <QFtp>
#include <QCoreApplication>
#include <stdio.h>

int main(int argc,char *argv[])
{
QCoreApplication app(argc,argv);
QFtp *ftp = new QFtp();
bool verify;
verify = 0;
printf("start ....\n");
verify=ftp->connectToHost(QString("172.16.41"));
if(!verify){printf("error in connecting\n");}else printf("connected \n");
verify=ftp->login("daredevil","9232575381");
if(!verify){printf("error in login\n");}else printf("login successfull \n");
verify=ftp->cd("Music");
if(!verify){printf("error in cd command\n");}else printf("cd successfull \n");
verify = ftp->get("youtube_pRpeEdMmmQ0.flv");
if(!verify){printf("error in get\n");}else printf("coppied \n");
ftp->close();
printf("successfully complete");
app.exec();
return 0;
}

calhal
8th July 2010, 10:17
Read the QFtp class description. Why are you assuming that connectToHost() will return 0 if something is wrong?

The function returns a unique identifier which is passed by commandStarted() and commandFinished().

And you can also read

The class works asynchronously, so there are no blocking functions. If an operation cannot be executed immediately, the function will still return straight away and the operation will be scheduled for later execution. The results of scheduled operations are reported via signals. This approach depends on the event loop being in operation.

So you have to process the signals, and probably you'll get QFtp::HostNotFound error.