PDA

View Full Version : QFtp Trouble !



Fastman
7th August 2007, 10:35
QT 4.3 +VS2005:



class CFtp: public QFtp
{
Q_OBJECT
public:
CFtp(QObject *parent = 0);
~CFtp();
qint16 ConnectToFTP(QString cFtpServer, QString cLogin, QString cPass);
void CloseFtp();
private:
QFtp *m_pFtp;
};




void CFtp::CloseFtp()
{
m_pFtp->close();

//if(m_pFtp != NULL)
//delete(m_pFtp);
}

qint16 CFtp::ConnectToFTP(QString cFtpServer, QString cLogin, QString cPass)
{
m_pFtp = new QFtp;

qint16 nStateConnect= -1;
qint16 nLoginConnect = -1;

nStateConnect = m_pFtp->connectToHost(cFtpServer);
nLoginConnect = m_pFtp->login(cLogin,cPass);

//QApplication::beep();

return 1;
}




void Connection::processReadyRead()
{
...
...
...
case 4: //DELETE FILE(4)
{

CFtp ftp;
ftp.ConnectToFTP("127.0.0.1","pas","amal");
ftp.CloseFtp();
}
break;
...
...
...
}




void FortuneThread::run()
{
Connection connection;
if(!connection.setSocketDescriptor(socketDescripto r))
{
emit error(connection.error());
return;
}
//connect(&connection, SIGNAL(SendMSG(QString)), this, SIGNAL(SendMSG(QString)));
connect(&connection, SIGNAL(disconnected()), this, SLOT(deleteConnection()));
exec();
}



But connection or occurs and hangs:

07/08/07 11:04:51, 499, 127.0.0.1, , new connection from 127.0.0.1 on 127.0.0.1:21
07/08/07 11:04:51, 499, 127.0.0.1, , hostname resolved : localhost
07/08/07 11:04:51, 499, 127.0.0.1, , sending welcome message.
07/08/07 11:04:51, 499, 127.0.0.1, , 220 Gene6 FTP Server v3.9.0 (Build 2) ready...

or it is not connected in general.
Connections are closed only after timeout or after closing the appendix.

jpn
7th August 2007, 13:05
Have you taken look at the FTP example (http://doc.trolltech.com/4.3/network-ftp.html)? Above snippet is a bit confusing. CFtp already is a QFtp so there is no need to wrap yet another QFtp as a member variable. Also, be aware that QFtp::connectToHost() does not block but returns immediately. Changes in connection state are informed later via signals.

marcel
7th August 2007, 13:08
Well, I already told you to move the connect statement from the Connection constructor.
Can you post the whole code now, because the parts you posted don't really show anything.

So, it is most likely a thread/synchronization problem.

Regards