[Qt-interest] QNetworkAccessManager and FTP woes

Robert Caldecott robert.caldecott at gmail.com
Thu Nov 26 15:38:23 CET 2009


I just downloaded the 4.6.0 RC and my example app now works fine.
Looks like this issue has already been addressed and I am am happy to
start using the RC as I'm sure it will be released pretty soon now...
:)

2009/11/25 Markus Goetz <Markus.Goetz at nokia.com>:
> ext Robert Caldecott wrote:
>>
>> 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()));
>>
>
> Can you send a complete minimal example? Maybe you are accidently
> delete()ing the upload file object somewhere?
>>
>> 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.
>>
>
> Strange.
>>
>> I have also tried reading the entire file into a QByteArray and using
>> the alternative QNetworkAccessManager::put function but I get the same
>> problem.
>
> For a QByteArray it should write the whole array to the socket at once, e.g.
> the stalling read() calls should be no problem:
> socket->write(data.ba->data(), data.ba->size());
> Or were you using a QBuffer (which is a QIODevice) to wrap the QByteArray
> and sent that?
>
> Markus
>
>
>




More information about the Qt-interest-old mailing list