[Qt-interest] QNetworkAccessManager and FTP woes

Robert Caldecott robert.caldecott at gmail.com
Wed Nov 25 22:04:11 CET 2009


I am home now but will post a full example tomorrow.

I have changed the code to use QFtp and it works fine.

I am sure no objects are being deleted prematurely.

When sending a QByteArray it still seems to send the data in 16Kb
chunks - I think the Qt code is wrapping the QByteArray with a
QIODevice object so it behaves in the same way as a 'real' file (from
what I could see of the source code.)

Out of interest, as I am using a QUrl to specify the ftp details, does
Qt default to performing an ASCII or binary transfer?  I doubt this is
relevant as it seems like a random amount of data is uploaded but I
thought it worth asking.

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