Results 1 to 20 of 20

Thread: Putting large size file on FTP using QNetworkAccessManager

  1. #1
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Putting large size file on FTP using QNetworkAccessManager

    We are facing issues when we are trying to send the file (text/image/exe) to the FTP server.

    We have used QFtp functions to put the file onto the server with user authentication. But QFtp is taking huge time to upload the files. Hence we moved to QNetworkAccessManager an have used the put method for uploading.

    QNetworkAccessManager::put() returns with a reply and finished is also triggered, but no file is getting uploaded.

    I have used the below code to put:
    Qt Code:
    1. QUrl uploadurl("ftp://server/dir/");
    2. uploadurl.setUserName("XXXXXX");
    3. uploadurl.setPassword("XXXXXX");
    4. uploadurl.setPort(21);
    5. QNetworkRequest upload(uploadurl);
    6. QNetworkAccessManager *uploadman = new QNetworkAccessManager(this);
    7.  
    8. QFile* file = new QFile("filepath");
    9. if(file->open(QFile::ReadOnly)) {
    10. uploadman->put(upload, file);
    11. }
    To copy to clipboard, switch view to plain text mode 

    Please help us out with the above issue. Any example code would be a great help.

    Thanks in advance.
    Last edited by darshan.hardas; 28th September 2012 at 21:22.
    Darshan

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Given that you are discarding the QNetworkReply* returned by put(), and not connecting the QNetworkAccessManager instance to anything I do not see how you can possibly know that finished() is being emitted and that no error is being returned.


    This code uploads just fine when the server permits it (and prints a non-zero error number if not):
    Qt Code:
    1. #include <QtCore>
    2. #include <QtNetwork>
    3. #include <QDebug>
    4.  
    5. class Uploader: public QObject
    6. {
    7. Q_OBJECT
    8. public:
    9. Uploader(QObject *p = 0): QObject(p) { }
    10.  
    11. void start(const QString &file) {
    12. QUrl url("ftp://localhost/incoming");
    13. url.setUserName("test");
    14. url.setPassword("password");
    15.  
    16. data = new QFile(file, this);
    17. if (data->open(QIODevice::ReadOnly)) {
    18. reply = nam.put(QNetworkRequest(url), data);
    19. connect(reply, SIGNAL(uploadProgress(qint64, qint64)), SLOT(uploadProgress(qint64, qint64)));
    20. connect(reply, SIGNAL(finished()), SLOT(uploadDone()));
    21. }
    22. else
    23. qDebug() << "Oops";
    24. }
    25.  
    26. public slots:
    27. void uploadProgress(qint64 bytesSent, qint64 bytesTotal) {
    28. qDebug() << "Uploaded" << bytesSent << "of" << bytesTotal;
    29. }
    30.  
    31. void uploadDone() {
    32. qDebug() << "Finished" << reply->error();
    33. data->deleteLater();
    34. reply->deleteLater();
    35. }
    36.  
    37. private:
    38. QNetworkAccessManager nam;
    39. QFile *data;
    40. QNetworkReply *reply;
    41. };
    42.  
    43. int main(int argc, char **argv)
    44. {
    45. QCoreApplication app(argc, argv);
    46. Uploader u;
    47. u.start("ten_meg_file.dat");
    48. return app.exec();
    49. }
    50. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Thanks for the input. I have not appended the file name to be uploaded in the QUrl formed. Now I can send the file to the FTP.

    I am not getting the speed while the FTP is done. If upload/download speed is compared with the other FTP clients like FileZilla, the file is taking too much of time. The network speed of the machine used is in some mbps still the speed is very slow for upload using QFTP or QNetworkAccessManager .

    Please let me know your valuable inputs.
    Darshan

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    How do you expect us to debug your network connection? How big is the file? What speed is the connection? How long does it actually take? What else is your program doing?

  5. #5
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    The logic is implemented to put the file onto the shared FTP folder.

    I have used QFtp and QNetworkAccessManger to put the file to the ftp. But the time taking to upload is very large. Compared to other FTP clients the time taken is just double the time taken.


    I have used the files upto 100 mb. For 100 Mb the time taken is approx 12 mins by QFTP/QNetworkAcessManager. But the ftp clients like FileZilla uploads the file in 3-4 mins.

    I would like to know if we can implement any caching or are there any params to optimize the upload.
    Darshan

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    No, you need to work out what your program is doing the rest of the time. Does uploading a 100MB file using my code take as long?

  7. #7
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    yes, the code snippet also takes the same time... uploads 100MB in 11-12mins.

    I have noticed that the file below 50MB gets uploaded faster as compared to large file. We can configure Qt for large file support but 100MB file is not considered as large file.
    Darshan

  8. #8
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    The code I gave you uploads 104857600 bytes on my LAN in 9.48 seconds average at approx 88 Mbps (i.e. saturating the 100Mbps LAN). The CPU effort barely registers. The result scales to a 1GB file in about 100 seconds.

    You are claiming about 1.3 Mbps as a Qt imposed limit when other program have no such limit. I don't think the problem is in Qt networking.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Which version of Qt are both of you guys using?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Qt 4.8.2 and Qt 5.0.0Beta1 on Linux talking to a pure-ftpd server on Linux.

    I just tried Qt 4.8.0 and Qt 4.7.4 on Windows XP (in a VM on Linux, same server) with the result of about 2100 ms for the 10MB file, 20500ms for the 100MB file. FileZilla on the same machine manages to match Linux; a shade under 10 seconds for the 100MB file. On Windows 7 the performance is even worse, although I cannot see an obvious cause.

    Looking with Wireshark: both transfers from Windows are in FTP passive mode. The data packets are the same size. The pattern of outgoing data an incoming ACK packets is quite different, with Qt bunching outgoing packets more than Filezilla. QTBUG-16359 may be pertinent

  11. #11
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    I also have tried with Qt 4.8.2, 4.7.4 on Windows. The transfer speed is very slow. We are also targeting to use the static libs of Qt. But firstly the transfer rate should fair enough to handle atleast 500 MB of file.
    Last edited by darshan.hardas; 4th October 2012 at 06:19.
    Darshan

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Quote Originally Posted by darshan.hardas View Post
    I also have tried with Qt 4.8.2, 4.7.4 on Windows. The transfer speed is very slow. We are also targeting to use the static libs of Qt. But firstly the transfer rate should fair enough to handle atleast 500 MB of file.
    So have you launched the application that Chris posted as-is or did you somehow changed it or incorporated it in your program?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    To be clear, my code example is markedly slower on Windows too. I tried 4.7.4 and 4.8.0 using MingW. I have not tried MSVC to see it it is a C++ runtime issue.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Quote Originally Posted by ChrisW67 View Post
    To be clear, my code example is markedly slower on Windows too.
    But not as slow as to transfer 100MB in 11-12 minutes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    No, granted. But I am working across a LAN, and the OP is not.
    Quote Originally Posted by Darshan
    For 100 Mb the time taken is approx 12 mins by QFTP/QNetworkAcessManager. But the ftp clients like FileZilla uploads the file in 3-4 mins.
    So, the "optimum" is about 3 times faster than the Qt program (500 vs 150 KB/s). This is not that dissimilar the slowdown factor I saw on a LAN connection with XP. Windows 7 was worse again.

  16. #16
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    I have used the code-as is posted. Also, have implemented the logic using QFtp.

    We are testing the speed using machine instances created on cloud (Amazon EC2). The network bandwidth is very high on both the instances i.e. client and server.
    Darshan

  17. #17
    Join Date
    Oct 2007
    Posts
    39
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Finally I have to try using the sockets QTcpSocket and have to implemented the whole FTP RFC to transfer the file. I have managed to read the file in the separate thread and storing it in buffer to be transfered onto the connection.

    This methodology have increased the upload speed and now I can transfer the 100 MB is 3-4 minutes.

    Thank you all for giving your inputs.
    Darshan

  18. #18
    Join Date
    Oct 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    This sounds like a lot of work, can we do something about this?

  19. #19
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    Hi, i have used your code, and get this error:

    [root@mcapro Upload]# ./Upload
    QIODevice::read: device not open
    Uploaded 0 of 0
    Finished 201

    The file exists and have size

  20. #20
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Putting large size file on FTP using QNetworkAccessManager

    The error message is clear, the file is not open. If you are using a relative path to open the file then it is likely that the current working directory of the process is not what you think it is.

Similar Threads

  1. Replies: 1
    Last Post: 19th March 2011, 02:42
  2. Qt displays large size jpg
    By omegas in forum Qt Programming
    Replies: 14
    Last Post: 22nd April 2010, 05:07
  3. To large exe file
    By wydesenej in forum Installation and Deployment
    Replies: 8
    Last Post: 24th January 2009, 21:44
  4. open large file in qt?
    By vishal.chauhan in forum Qt Programming
    Replies: 11
    Last Post: 29th May 2007, 07:25
  5. QLabel, large, rich text, font size
    By TheKedge in forum Qt Programming
    Replies: 3
    Last Post: 5th February 2007, 11:56

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.