Results 1 to 3 of 3

Thread: Reading file's content from ftp.

  1. #1
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Reading file's content from ftp.

    Hi.

    I'm using Qt 4.4.3 and try to read file's content from ftp server and show it with QTextEdit.

    Qt Code:
    1. QBuffer file;
    2. file.open(QIODevice::ReadWrite | QIODevice::Text);
    3. file.setObjectName(fileName);
    4.  
    5. ftp->setTransferMode(QFtp::Passive);
    6. ftp->connectToHost("192.168.10.17", 21);
    7. ftp->login();
    8. ftp->get(fileName, &file);
    9.  
    10. QString lines;
    11. QTextStream in(&file);
    12. while (!in.atEnd()) {
    13. lines = in.readAll();
    14. textEdit->setText(lines);
    15. }
    16.  
    17. file.close();
    18. ftp->close();
    To copy to clipboard, switch view to plain text mode 

    Above code shows nothing. I mean, textEdit is empty.

    Outputs from ftp server are:
    RETR test.diag
    150 Opening data connection
    Successfully sen file 'c:\ftproot\test.diag' (1112129 B sent)
    226 transfer complete
    And from my console:
    Command Finished! Id:1-Status:0
    Connection State Changed->1 Status: Host Lookup
    Connection State Changed->2 Status: Connecting
    Connection State Changed->3 Status: Connected
    Command Finished! Id:2-Status:0
    Connection State Changed->4 Status: Login
    Command Finished! Id:3-Status:0
    Transferred Data: 0
    Remaining: 1112129
    ...
    Transferred Data: 1112129
    Remaining: 1112129
    Connection State Changed->0 Status: Unconnected
    Connection State Changed->5 Status: Closing
    Any ideas what am I missing here?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reading file's content from ftp.

    QFtp::get() is an asynchronous operation.

    You have to wait for it to finish before you attempt reading the output buffer. See QFtp::commandFinished()

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    betees (20th November 2013)

  4. #3
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Reading file's content from ftp.

    Of course, thanks!

Similar Threads

  1. QMake Reading content from a file in qmake
    By MarcoAlanen in forum Qt Tools
    Replies: 2
    Last Post: 27th August 2014, 07:47
  2. Replies: 1
    Last Post: 22nd May 2012, 01:28
  3. QWebView Reading content shown by Javascript
    By lhg in forum Qt Programming
    Replies: 0
    Last Post: 14th October 2011, 19:00
  4. Replies: 11
    Last Post: 10th February 2011, 00:38
  5. Problems reading content of QFile
    By martinn in forum Newbie
    Replies: 12
    Last Post: 6th April 2010, 18:42

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
  •  
Qt is a trademark of The Qt Company.