[Qt-interest] QNetworkAccessManager and FTP woes

Robert Caldecott robert.caldecott at gmail.com
Wed Nov 25 15:25:57 CET 2009


I am trying to upload files to an FTP server using
QNetworkAccessManager (instead of using QFtp as recommended by the Qt
documentation.)  I am using Qt 4.5 on Windows XP and am attempting to
upload files to an IIS FTP server.

The problem I am having is that sometimes the upload just stops - no
'error' or 'finished' signal is sent - the process just doesn't
complete.  This seems to happen 90% of the time if the file size I am
uploaded exceeds 16Kb.  This is driving me nuts and I wonder if using
QNetworkAccessManager for FTP uploads was the right decision.  Note
also that I am trying to upload binary files.

Here is some sample code:

  QNetworkAccessManager* manager = new QNetworkAccessManager(this);
  QFile* file = new QFile("c:/tmp/somefile.exe");
  file->open(QIODevice::ReadOnly);

  QNetworkReply* reply =
manager->put(QNetworkRequest(QUrl("ftp://server/folder/somefile.exe")),
file);
  connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this,
SLOT(uploadProgress(qint64,qint64)));
  connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this,
SLOT(error(QNetworkReply::NetworkError)));
  connect(reply, SIGNAL(finished()), this, SLOT(finished()));

I have added some debug output to my slots and I usually see something
like this:

  uploadProgress  16384   2490368
  uploadProgress  32768   2490368

i.e. In this case am trying to PUT a 2490368 byte file.  The above is
all I see - no finished or error slots are called - the process just
seems to stall.

Does anyone know what I am doing wrong before I try QFtp instead?  Is
IIS going to be a problem (I hope not!!!).  Does the Qt 4.6 RC fix
anything in this area?

I traced into the core Qt code and the problem seems to be in QFtp.cpp
- the QFtpDTP::writeData() function contains the following code:

  qint64 read = data.dev->read(buf, blockSize);

And sometimes this returns 0 - for no reason that I can see.  This
scuppers the upload process.

I have also tried reading the entire file into a QByteArray and using
the alternative QNetworkAccessManager::put function but I get the same
problem.  I also tried specifying QIODevice::Unbuffered when I opened
the file but this makes no difference.

Any advice would be welcome.



More information about the Qt-interest-old mailing list