Results 1 to 3 of 3

Thread: Sending Binary File with QFTP

  1. #1
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Question Sending Binary File with QFTP

    I know this is a Major Noob question, but all the examples i can find are of an FTP GET not an FTP PUT. I have several of the books on QT, nothing on Opening a file and PUTing it..


    All i want to do is see some examples of opening a file and using QFTP PUTing it to a remote ftp as anonymous

    The transfer must be binary safe.

    I have this code to update a combo box with a filename from a browse button...
    Qt Code:
    1. void Window::browse()
    2. {
    3. QString directory = QFileDialog::getOpenFileName(this,
    4. tr("Open File"), QDir::currentPath());
    5. if (!directory.isEmpty()) {
    6. directoryComboBox->addItem(directory);
    7. directoryComboBox->setCurrentIndex(directoryComboBox->currentIndex() + 1);
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 

    This works fine, then when they push Send it calls "sendFile", but I cannot link the "directoryComboBox" to the QFTP PUT... and send it to the server.

    Send File Code...
    Qt Code:
    1. void Window::sendFile()
    2. {
    3.  
    4. cancelButton->setEnabled(true);
    5.  
    6. ftp = new QFtp(this);
    7.  
    8. /* This holds the remote server IP Address */
    9. ftp->connectToHost(printerComboBox->currentText());
    10.  
    11. /* These Status labels are broken they work but show sending file allways, need to do better checking later */
    12. statusLabel->setText(tr("Connecting to printer at %1 using FTP")
    13. .arg(printerComboBox->currentText()));
    14. ftp->login();
    15.  
    16. statusLabel->setText(tr("%1 - Logging in...")
    17. .arg(printerComboBox->currentText()));
    18.  
    19. /* NEED TO REPLACE THIS WITH THE PROPER FILE OPEN AND SEND */
    20. ftp->list();
    21.  
    22. statusLabel->setText(tr("%1 - Sending File...")
    23. .arg(printerComboBox->currentText()));
    24. }
    To copy to clipboard, switch view to plain text mode 

    I put in the "list();" command where the FTP PUT should be to make sure that the QFTP was doing something on the network, which it does. Now i need to actually open the file and send it.

    Thanks all, this is my first ... Real (one that does something) QT network APP. Thanks for the assistance.

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

    Default Re: Sending Binary File with QFTP

    Try something like this:
    Qt Code:
    1. QFile *file = new QFile("filepath", this);
    2. file->open(QFile::ReadOnly);
    3. ftp->put(file, "remotefilename");
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2007
    Posts
    59
    Thanks
    7

    Default Re: Sending Binary File with QFTP

    works perfectly, I now have my first "real" C++ app... (something that isnt "hello world"!)

Similar Threads

  1. File Binary Upload QHttp find the bug/s
    By patrik08 in forum Qt Programming
    Replies: 13
    Last Post: 10th June 2008, 07:51
  2. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  3. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23
  4. Replies: 11
    Last Post: 4th July 2006, 15:09
  5. xml with binary question
    By TheKedge in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2006, 23:21

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.