PDA

View Full Version : QFtp disconnected from server



cutie.monkey
19th May 2009, 06:32
hi all,..

i have a small FTP program which is based from FTP example.. now, what i encountered is that every 5 mins, my FTP program is disconnected from the server.. I tried this with 2 different FTP server and the same problem occurs..

wysota
19th May 2009, 08:27
The servers probably have timeouts set for 5 minutes... Can you be more specific about what happens? Did you try connecting using a commandline ftp client and wait 5 minutes to see what happens?

cutie.monkey
20th May 2009, 06:12
hi, thnks for the reply..
anyway, heres my code in connecting to the ftp server:



void ftpagentclass::ftpPutConnectToFtp()
{
ftpPut = new QFtp();
connect(ftpPut, SIGNAL(stateChanged(int)), this, SLOT(ftpPutStateChanged(int)));

ftpPut->connectToHost(sample.ftp.server,21);
ftpPut->login(USERNAME, PASSWORD );
ftpPut->setTransferMode(QFtp::Passive);
}


in my ftpPutStateChanged(int):



void ftpagentclass::ftpPutStateChanged(int state)
{
switch(state){
case QFtp::Unconnected:
qDebug() << "FTP PUT: Unconnected!";
if(LOGIN)
logToMonitor("Disconnected from server!", "red");
else
logToMonitor("Can't connect to server.", "red");

logToMonitor("Reconnecting...", "yellow");
LOGIN = false;
ftpPutConnectToFtp(); //reconnect to server if disconnected
break;
case QFtp::HostLookup:
qDebug() << "FTP PUT: Host Lookup";
logToMonitor("Looking for server " + SERVER, "yellow");
LOGIN = false;
break;
case QFtp::Connecting:
qDebug() << "FTP PUT: Connecting";
logToMonitor("Connecting...", "yellow");
LOGIN = false;
break;
case QFtp::Connected:
qDebug() << "FTP PUT: Connected";
logToMonitor("Connection established!", "green");
logToMonitor("Logging in...", "green");
LOGIN = false;
break;
case QFtp::LoggedIn:
qDebug() << "FTP PUT: LoggedIn";
logToMonitor("Logged In successful!", "green");
LOGIN = true;
break;
case QFtp::Closing:
qDebug() << "FTP PUT: Closing";
LOGIN = false;
break;
default:
qDebug() << "FTP PUT: Unknown error!";
logToMonitor("Unknown error occured!", "red");
LOGIN = false;
break;
}
}


Now, what i encountered is that when my program is connected to ftp server, after 5 mins, it will be disconnected, so i have to reconnect it again.. i didn't add any timeout... do i miss something in my code? thnks

wysota
20th May 2009, 08:23
Please do as I said - connect to the same server with telnet to the ftp port (and/or a commandline ftp client) and see if you also get disconnected after 5 minutes.

cutie.monkey
20th May 2009, 10:27
hi!..

i do what you have instructed me, that is connecting to the ftp server through command prompt in windows, and i experienced the same problem.. it is also disconnected after 5 mins.. what do you think the cause of this problem? again thnks..

wysota
20th May 2009, 11:46
The server disconnects you after 5 minutes of inactivity. That's perfectly normal. If you want to prevent that, you can issue some command to the server from time to time (such as pwd) to keep the connection alive.