Results 1 to 5 of 5

Thread: how to use qftp to upload file in just one procedure?

  1. #1
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default how to use qftp to upload file in just one procedure?

    I just want to use qftp to upload a file .at first , i have to determine whether the dir exists or not. But how to implement the code to judge and at the same time upload file in one function?
    just like that :
    Qstringlist dirlist;
    ftp.list(dirlist) ;
    if (!dirlist.contain(onedir))
    {
    ftp.mkdir(onedir);
    }
    ftp.put(myFile) ;

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use qftp to upload file in just one procedure?

    Not sure what you mean. What is wrong with the code you posted?

  3. #3
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: how to use qftp to upload file in just one procedure?

    before upload a file ,i want to determine if the parent dir existed . but how to do it? i know the flowing code will not work.

    Qt Code:
    1. bool frmMainWindow::upLoadFile(QString checkcode,QString filename)
    2. {
    3. ftp = new QFtp(this);
    4. connect(ftp, SIGNAL(commandFinished(int, bool)),
    5. this, SLOT(ftpCommandFinished(int, bool)) );
    6. connect(ftp, SIGNAL(listInfo(const QUrlInfo &)),
    7. this, SLOT(ftpListInfo(const QUrlInfo &)));
    8. connect(ftp, SIGNAL(dataTransferProgress(qint64, qint64) ),
    9. this, SLOT(updateDataTransferProgress(qint64, qint64)));
    10.  
    11. ftp->connectToHost("192.168.1.3");
    12. ftp->login("ftpuser","ftpuser");
    13. fileList.clear();
    14. ftp->cd("/pisdata/"); //init dir
    15. ftp->list();
    16.  
    17. QString taskcode;
    18. taskcode=checkcode.left(8);
    19.  
    20. //first to determine if parent dir exits.
    21. if (!fileList.contains(taskcode)){ [COLOR="Red"] //fileList will not contain anything [/COLOR]
    22. ftp->mkdir(taskcode);
    23. ftp->cd(taskcode);
    24. ftp->mkdir("pdf");
    25. ftp->mkdir("image");
    26. ftp->mkdir("xml");
    27. ftp->cd("image");
    28. }
    29. else{
    30. ftp->cd(taskcode);
    31. fileList.clear();
    32. ftp->list();
    33. if(!fileList.contains("image",Qt::CaseInsensitive)){
    34. ftp->mkdir("image");
    35. }
    36. ftp->cd("image");
    37. }
    38. //////////////start upload file////////
    39. QString ftpPath;
    40. ftpPath="/pisdata/"+taskcode;
    41. ftpPath+="/image/";
    42. ftp->cd(ftpPath);
    43. //QFile file(filename);
    44. file=new QFile(filename);
    45. if (!file->open(QIODevice::ReadOnly))
    46. {
    47. file->close();
    48. delete file;
    49. return false;
    50. }
    51. QFileInfo fi(filename);
    52. ftp->put(file,fi.fileName());
    53. progressDialog->setLabelText(tr("put %1...").arg(fi.fileName()));
    54. progressDialog->exec();
    55.  
    56. return true;
    57. }
    58.  
    59. void frmMainWindow::ftpListInfo(const QUrlInfo &urlInfo)
    60. {
    61. fileList<<urlInfo.name() ;
    62. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to use qftp to upload file in just one procedure?

    The problem is that you do not wait for the ftp commands to complete ( either success or fail ). You do everything at once.

    You should wait for every ftp command to complete and then go to next step.
    You should make use of the commandStarted and commandFinished signals and queue the command id's as soon as you execute them( for list, mkdir, etc ).

    Currently when you search in the file list it will be empty, because the list() command has not completed yet.

    Regards

  5. #5
    Join Date
    Dec 2006
    Posts
    36
    Thanked 1 Time in 1 Post

    Default Re: how to use qftp to upload file in just one procedure?

    yes, i know the reason.But how should i do ? write the code in ftpCommandFinished ?

Similar Threads

  1. Stored procedure and ODBC
    By filya in forum Qt Programming
    Replies: 2
    Last Post: 15th March 2010, 08:40
  2. File Binary Upload QHttp find the bug/s
    By patrik08 in forum Qt Programming
    Replies: 13
    Last Post: 10th June 2008, 07:51
  3. qftp in qthread canot upload file
    By cxl2253 in forum Qt Programming
    Replies: 16
    Last Post: 7th April 2007, 02:44
  4. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10
  5. QHttp "PUT METHOD" QT Problem File Upload. RFC 2616
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 25th October 2006, 22:02

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.