[Qt-interest] QNetworkAccessManager and FTP woes
Robert Caldecott
robert.caldecott at gmail.com
Thu Nov 26 10:56:22 CET 2009
Attached is a small sample that demonstrates the problem. Is this
example the code attempts to upload an EXE to a local FTP server. I
am using IIS 5.1. Also attached is a screen shot of the problem I see
- a number uploadProgress signals are emitted (sometimes just one or
two, sometimes more) but then the process just stops.
If I change the code to use QFtp instead, all is well. I can supply
an example of this if required.
Regards.
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
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FTP.zip
Type: application/zip
Size: 1999 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/b679cbc6/attachment.zip
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ftp.png
Type: image/png
Size: 16388 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091126/b679cbc6/attachment.png
More information about the Qt-interest-old
mailing list