From 4aa41982401213c67f8e4dbd6712b732fd5aa663 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Tue, 18 Oct 2011 16:18:06 +0100 Subject: FTP - fix interoperability issues with SIZE command Certain FTP servers refuse the SIZE command in ASCII mode (proftpd) or refuse the SIZE command in ASCII mode for large files. This is a security feature, as the SIZE command requires reading the whole file and counting line ends which can cause denial of services. In binary mode, the file size on disc is reported, which is a relatively quick operation. Qt had two problems here: 1. when size command fails, the total size was reported as -1, whereas the documentation of QFtp::dataTransferProgress states it should be reported as 0 (so that QProgressDialog can display a wait note rather than progress bar) 2. SIZE command was sent before setting the type of the transfer to ASCII / Binary. This is a problem as the size reported by the server is incorrect. Also it usually means sending ASCII SIZE for Binary transfers, which results in the 550 error on FTP servers with DOS protection. Task-Number: QTTH-1428 Reviewed-By: Peter Hartmann (cherry picked from commit 72bf6105214bfc26cff33632f7f4bdeed9cdf362) Change-Id: Ie1f356c34d6a04362eaca64befb00788f85c0ccb Reviewed-by: Peter Hartmann --- src/network/access/qftp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index 49b7e3f10d..eaed4dff5a 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -1821,11 +1821,11 @@ int QFtp::cd(const QString &dir) int QFtp::get(const QString &file, QIODevice *dev, TransferType type) { QStringList cmds; - cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n"); if (type == Binary) cmds << QLatin1String("TYPE I\r\n"); else cmds << QLatin1String("TYPE A\r\n"); + cmds << QLatin1String("SIZE ") + file + QLatin1String("\r\n"); cmds << QLatin1String(d_func()->transferMode == Passive ? "PASV\r\n" : "PORT\r\n"); cmds << QLatin1String("RETR ") + file + QLatin1String("\r\n"); return d_func()->addCommand(new QFtpCommand(Get, cmds, dev)); @@ -2301,7 +2301,7 @@ void QFtpPrivate::_q_piError(int errorCode, const QString &text) // non-fatal errors if (c->command == QFtp::Get && pi.currentCommand().startsWith(QLatin1String("SIZE "))) { - pi.dtp.setBytesTotal(-1); + pi.dtp.setBytesTotal(0); return; } else if (c->command==QFtp::Put && pi.currentCommand().startsWith(QLatin1String("ALLO "))) { return; -- cgit v1.2.3