hi, thnks for the reply..
anyway, heres my code in connecting to the ftp server:
void ftpagentclass::ftpPutConnectToFtp()
{
connect(ftpPut, SIGNAL(stateChanged(int)), this, SLOT(ftpPutStateChanged(int)));
ftpPut->connectToHost(sample.ftp.server,21);
ftpPut->login(USERNAME, PASSWORD );
ftpPut
->setTransferMode
(QFtp::Passive);
}
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);
}
To copy to clipboard, switch view to plain text mode
in my ftpPutStateChanged(int):
void ftpagentclass::ftpPutStateChanged(int state)
{
switch(state){
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;
qDebug() << "FTP PUT: Host Lookup";
logToMonitor("Looking for server " + SERVER, "yellow");
LOGIN = false;
break;
qDebug() << "FTP PUT: Connecting";
logToMonitor("Connecting...", "yellow");
LOGIN = false;
break;
qDebug() << "FTP PUT: Connected";
logToMonitor("Connection established!", "green");
logToMonitor("Logging in...", "green");
LOGIN = false;
break;
qDebug() << "FTP PUT: LoggedIn";
logToMonitor("Logged In successful!", "green");
LOGIN = true;
break;
qDebug() << "FTP PUT: Closing";
LOGIN = false;
break;
default:
qDebug() << "FTP PUT: Unknown error!";
logToMonitor("Unknown error occured!", "red");
LOGIN = false;
break;
}
}
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;
}
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks