Results 1 to 3 of 3

Thread: QFtp upload file to server

  1. #1
    Join Date
    May 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QFtp upload file to server

    Hi,
    I use QFtp class in order to upload my files to server but after ftp->put I find that files are empty in server
    I do not understand what is the problem in the code
    My code is here
    Qt Code:
    1. QFtp *ftp = new QFtp(this);
    2. ftp->setTransferMode(QFtp::Passive);
    3. //connect(ftp,SIGNAL(commandFinished ( int, bool)),this,SLOT(fincommande()));
    4. ftp->connectToHost("ftp.icwus.net",21);
    5. //setValueProgressBar(25);
    6.  
    7. connect(ftp, SIGNAL(stateChanged(int)), this, SLOT(showNewState(int)));
    8.  
    9. connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp_commandFinished( int, bool )) );
    10. connect( ftp, SIGNAL( commandFinished( int, bool )),this, SLOT( ftp1_commandFinished( int, bool )) );
    11.  
    12. ftp->login("mylogin","mypassword");
    13. ftp->cd("acrgafsa");
    14. ftp->mkdir("timetables");
    15. ftp->cd("timetables");
    16.  
    17. int i = 0;
    18. QString filename;
    19. QString files = QFileDialog::getOpenFileName(this, tr("Select File"),
    20. "D://");
    21.  
    22. if (files.isEmpty())
    23. return;
    24.  
    25. while(files.indexOf("/", i) != (-1)) //find the file name not include the full url
    26. i = files.indexOf("/",i) + 1;
    27. while(i < files.size())
    28. {
    29. filename.append(files.at(i));
    30.  
    31. i++;
    32. }
    33.  
    34. QFile *file = new QFile(filename);
    35.  
    36. Q_ASSERT(file != NULL);
    37.  
    38. if(!file->open(QIODevice::ReadWrite)) //finished create the file in the debug file
    39. {
    40. qDebug() << "opern err" << file->fileName();
    41. return;
    42. }
    43.  
    44. ftp->put(file,filename);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    506
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QFtp upload file to server

    Hi, do you reach the ftp_commandFinished() slot? Does its bool parameter indicate success?

    Ginsengelf

  3. #3
    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: QFtp upload file to server

    This is what is see when I read through your program:
    • Ask the user for a source file name and get a full path [19]
    • Use a non-portable method to find the base name of the source file [25-32] and throw away the full path. Try QFileInfo.
    • Allocate QFile object on the heap and use the base name of the source file [34]. Do you ever free this memory?
    • Check for a null return from the new call [36]. By default C++ will throw std::bad_alloc if new fails and this line will never be reached.
    • Open that file using ReadWrite mode, in spite of the obvious need only to read [38]. The file with the specified name does not exist in the current working directory but will be created because you said you want to write to it. The open does not fail.
    • You put() the empty file [44]
    • The server gets an empty file

    Seems like everything is working as coded.

Similar Threads

  1. Upload file to HTTP server
    By produktdotestow in forum Qt Programming
    Replies: 5
    Last Post: 30th July 2011, 14:18
  2. How to upload file to HTTP server (POST Method)
    By Alex Snet in forum Qt Programming
    Replies: 8
    Last Post: 24th January 2011, 22:49
  3. QFtp:upload file to server
    By ensky_cy in forum Qt Programming
    Replies: 6
    Last Post: 14th December 2009, 10:42
  4. how to use qftp to upload file in just one procedure?
    By cxl2253 in forum Qt Programming
    Replies: 4
    Last Post: 23rd April 2007, 09:57
  5. qftp in qthread canot upload file
    By cxl2253 in forum Qt Programming
    Replies: 16
    Last Post: 7th April 2007, 02:44

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.