Hi, i need to implement a ftp client that has a resume upload feature using QFtp.
I have tried implementing the resume function using raw commands ... something like the following:
ftp->rawCommand("TYPE I");
ftp->rawCommand("PASV");
ftp->rawCommand("REST" + x); //where x is the string with the position ...
ftp->rawCommand("STOR" + remoteFileName);
ftp->rawCommand("TYPE I");
ftp->rawCommand("PASV");
ftp->rawCommand("REST" + x); //where x is the string with the position ...
ftp->rawCommand("STOR" + remoteFileName);
To copy to clipboard, switch view to plain text mode
however i am getting the following error:
425 :: "Can't open data connection."
I have looked over the QFtp sourcefile and i saw that the ftp data channel isn't opened when using raw commands.
I have tried opening a data channel using a QTcpSocket like this :
void FtpClass
::onRawCmdReply(int replyCode,
const QString & detail
) {
qDebug() << replyCode << " :: " << detail;
if (replyCode == 227) // detail = Entering Passive Mode (a1,a2,a3,a4,p1,p2)
// host = a1.a2.a3.a4
// port = p1*256 + p2
{
if (addrPortPattern.indexIn(detail) == -1)
{
{
qDebug("QFtp: bad 227 response -- address and port information missing");
}
}
else
{
quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt();
_dataSocket->connectToHost(host, port);
if (!_dataSocket->waitForConnected(1000))
{
qDebug() << "cannot connect to: " << host << "port :" << port;
}
else
{
qDebug() << "connected to: " << host << "port :" << port;
}
}
}
}
void FtpClass::onRawCmdReply(int replyCode, const QString & detail )
{
qDebug() << replyCode << " :: " << detail;
if (replyCode == 227) // detail = Entering Passive Mode (a1,a2,a3,a4,p1,p2)
// host = a1.a2.a3.a4
// port = p1*256 + p2
{
QRegExp addrPortPattern(QLatin1String("(\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)"));
if (addrPortPattern.indexIn(detail) == -1)
{
{
qDebug("QFtp: bad 227 response -- address and port information missing");
}
}
else
{
_dataSocket = new QTcpSocket(this);
QStringList lst = addrPortPattern.capturedTexts();
QString host = lst[1] + QLatin1Char('.') + lst[2] + QLatin1Char('.') + lst[3] + QLatin1Char('.') + lst[4];
quint16 port = (lst[5].toUInt() << 8) + lst[6].toUInt();
_dataSocket->connectToHost(host, port);
if (!_dataSocket->waitForConnected(1000))
{
qDebug() << "cannot connect to: " << host << "port :" << port;
}
else
{
qDebug() << "connected to: " << host << "port :" << port;
}
}
}
}
To copy to clipboard, switch view to plain text mode
But if i do that i get the following error :
426 :: "Connection closed; transfer aborted."
It is not a server issue since i've tested using a random ftp client and the server supports resuming.
Also it is not a firewall issue since i dissabled the firewalls on both machines.
What am i doing wrong ? can someone help me please?
Bookmarks