The file size I try to ftp is around 10,000 byte counts, if this information is helpful. Your sample xml file size perhaps is too small (my random thought).
I didn't block each file, instead I submit all ftp jobs, and then wait until all finish or timeout.
However, it is more serious for 201 error caused by 203 error. I switch to Qt 5.2, same problem exists.
#include <QtCore>
#include <QtNetwork>
#include <QDebug>
int main(int argc, char **argv)
{
QNetworkAccessManager manager;
QObject::connect(&manager,
SIGNAL(finished
(QNetworkReply
*)),
&eventLoop,
SLOT(quit
()));
QList<QNetworkReply*> replies;
int loops = 200;
for ( int idx = 0; idx < loops; idx++ ) {
/// let's ftp same file 200 times and compare them
/// (But I just got first file, why?)
QUrl url
( "ftp://mirror.internode.on.net/pub/gentoo-portage/dev-qt/assistant/metadata.xml" );
url.setUserName( "anonymous" );
url.setPassword( "anon@example.com" );
replies << manager.get( QNetworkRequest( url ) );
}
/// you need to set time out before exec is call
/// allow 60 seconds timeout for each ftp
QTimer::singleShot( loops
* 60 * 1000,
&eventLoop,
SLOT( quit
() ) );
/// block until all files area finished
eventLoop.exec();
qDebug() << "done";
qDebug() << ba0;
for ( int idx = 1; idx < loops; idx++ ) {
if ( ba0.size() != ba.size() ) {
qDebug() << idx << ": Size not equal";
qDebug() << ba;
break;
}
}
return 0;
}
#include <QtCore>
#include <QtNetwork>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QNetworkAccessManager manager;
QEventLoop eventLoop;
QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
QList<QNetworkReply*> replies;
int loops = 200;
for ( int idx = 0; idx < loops; idx++ ) {
/// let's ftp same file 200 times and compare them
/// (But I just got first file, why?)
QUrl url( "ftp://mirror.internode.on.net/pub/gentoo-portage/dev-qt/assistant/metadata.xml" );
url.setUserName( "anonymous" );
url.setPassword( "anon@example.com" );
replies << manager.get( QNetworkRequest( url ) );
}
/// you need to set time out before exec is call
/// allow 60 seconds timeout for each ftp
QTimer::singleShot( loops * 60 * 1000, &eventLoop, SLOT( quit() ) );
/// block until all files area finished
eventLoop.exec();
qDebug() << "done";
QByteArray ba0 = replies.at( 0 )->readAll();
qDebug() << ba0;
for ( int idx = 1; idx < loops; idx++ ) {
QByteArray ba = replies.at( idx )->readAll();
if ( ba0.size() != ba.size() ) {
qDebug() << idx << ": Size not equal";
qDebug() << ba;
break;
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks