QFtp - problem with access to received data invoked by raw command
-
Hello,
I have problem. I need transfer part(end) of file by using FTP (reason is interrupt precede transfer). I execute it in separate thread.
Getting end of file allows FTP protocol only by using raw commands. So I am forced to use it.
My problem is, that I don’t know how access to received data, because methods connected to signals (dataTransferProgress, readyRead) aren’t invoked.
Extract important parts of program :@void CWSTransact::FtpDataTransferProgress
(
qint64 x_i64readBytes, ///< Read bytes
qint64 x_i64totalBytes ///< Total bytes
)
{
qDebug () << "updateDataTransferProgress " << x_i64readBytes << " " << x_i64totalBytes;
}
void CWSTransact::FtpReadyRead ()
{
qDebug () << "FtpReadyRead";
......
}
void CWSTransact::FtpStateChanged
(
int x_iState ///< New state of FTP
)
{
qDebug () << "CWSTransact : State change = " << x_iState;
}
void CWSTransact::FtpRawCommandReply
(
int x_iCode, ///< Reply code
const QString & x_roDetail ///< Details
)
{
qDebug () << "CWSTransact : RawCommandReply = " << x_iCode << " ; " << x_roDetail;
}............
m_poFtp = new QFtp (this); // Create FTP object
// connect to slots of ftp
connect(m_poFtp, SIGNAL(commandFinished(int,bool)),
this , SLOT (FtpCommandFinished(int,bool)));
connect(m_poFtp, SIGNAL(dataTransferProgress(qint64,qint64)),
this , SLOT (FtpDataTransferProgress(qint64,qint64
connect(m_poFtp, SIGNAL(readyRead()),
this , SLOT (FtpReadyRead()));
connect(m_poFtp, SIGNAL(stateChanged(int)),
this , SLOT (FtpStateChanged(int)));
connect(m_poFtp, SIGNAL(stateChanged(int)),
this , SLOT (FtpStateChanged(int)));
connect(m_poFtp, SIGNAL(listInfo(const QUrlInfo &)),
this , SLOT (FtpListInfo(const QUrlInfo &)));
connect(m_poFtp, SIGNAL(rawCommandReply(int, const QString &)),
this , SLOT (FtpRawCommandReply(int, const QString &)));a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->setTransferMode (QFtp::Passive);
a_poEventLoop->exec(); // waiting for end of command. because it is executed in thread
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->connectToHost ("localhost", 21);
a_poEventLoop->exec();
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->login (QString ("USER"), QString ("PASS"));
a_poEventLoop->exec(); // waiting for end of command
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->rawCommand (QString ("PASV"));
a_poEventLoop->exec();
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->rawCommand (QString ("TYPE I"));
a_poEventLoop->exec();
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->rawCommand (QString ("CWD temp"));
a_poEventLoop->exec();
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
QString a_oS = "pixm.bmp";
m_poFtp->rawCommand (QString ("SIZE %1").arg (a_oS));
a_poEventLoop->exec();
delete a_poEventLoop;// !!!!! set offdet in file
a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->rawCommand (QString ("REST 1000"));
a_poEventLoop->exec();
delete a_poEventLoop;a_poEventLoop = new QEventLoop ();
connect(m_poFtp, SIGNAL(commandFinished(int,bool)), a_poEventLoop, SLOT(quit()));
m_poFtp->rawCommand (QString ("RETR %1").arg (a_oS));
a_poEventLoop->exec();
delete a_poEventLoop;
@1) In log of local FTP server I see that data of required file was transferred.
2) On console of application I see answered :CWSTransact : RawCommandReply = 227 ; "Entering Passiv Mode (127,0,0,1,8,0)"
CWSTransact : RawCommandReply = 200 ; "Type successfully set"
CWSTransact : RawCommandReply = 250 ; "Directory change OK"
CWSTransact : RawCommandReply = 213 ; "88830"
CWSTransact : RawCommandReply = 350 ; "Restarting at 1000, send RETR or STOR
command to start transfer"
CWSTransact : RawCommandReply = 150 ; "Data connection created for /temp/pixm
.bmp retrieving"I didn’t receive any signals with data information. So I tried wait several seconds and try call bytesAvailable (). Bat no received data was detected.
If I use instead sequence od raw commands simple call get() method, so everything is passed right.
Have anybody any advice, pleaseb ?