Results 1 to 3 of 3

Thread: QFtp : Uploading a directory

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2006
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Thumbs up QFtp : Uploading a directory

    Hi all,

    Here is my problem:

    Purpose:- Upload a directory from local host to remote machine (remote ftp server)

    Qt Class in use:- QFtp Class

    Problem:-
    Source code given below, works fine if I put QmessageBox after line:
    ftp->mkdir(directoryName);
    Otherwise I get the error-
    Changing directory failed:
    Failed to change directory.

    Source Code:-
    Qt Code:
    1. uploadDirectory(QDir dir){
    2.  
    3. QString absPath=dir.absPath();
    4.  
    5. QString directoryName=absPath.section('/',-1);
    6. dir.setSorting(QDir::DirsFirst);
    7. const QFileInfoList *localFileInfoList = dir.entryInfoList();
    8.  
    9. QFileInfoListIterator fileIterator(*localFileInfoList );
    10. int count=localFileInfoList->count();
    11.  
    12. QFileInfo* file;
    13. int mkdirFlag =1;
    14.  
    15. for(int temp=0;temp<count;temp++) {
    16.  
    17. file=fileIterator.current();
    18. if(mkdirFlag){
    19.  
    20. ftp->rawCommand( "PWD" );
    21. ftp->mkdir(directoryName);
    22. mkdirFlag=0;
    23. currentDir->cd(directoryName);
    24. QString ftpString=ftpDir+QString("/")+directoryName;
    25. ftp->cd(ftpString);
    26.  
    27. }
    28.  
    29. if(file->isDir() && file->fileName()!="." && file->fileName()!=".."){
    30. uploadDirectory(QDir(currentDir->absPath()+QString("/")+QString(file->fileName())));
    31.  
    32. }
    33. if(!file->isDir())
    34. uploadFile(currentDir->absPath()+QString("/")+file->fileName());
    35.  
    36. ++fileIterator;
    37. }
    38. ftp->cd("..");
    39.  
    40. currentDir->cdUp();
    41. }
    To copy to clipboard, switch view to plain text mode 

    Description:-
    ftp:-denotes the remote ftp(Class QFtp)
    currentDir:-denotes the current local directory(QDir)
    ftpDir:-denotes current remote file path (QString)
    Note: - we get this value by sending PWD command( ftp->rawCommand( "PWD") ) in the command reply function we set this value in ftpDir
    directoryName:- if dir is “home/username/folder1” then directoryName gives folder1
    uploadFile() function uploads the given file

    Observation:-
    It takes time to complete the function like get, put, mkdir, cd etc. and these functions are nonblocking. Program doesn’t block here. Just take an example if I call ‘mkdir’ (ftp->mkdir()) then program doesn’t wait for completion of this function. It goes to next line and performs (ftp->cd()) and I get the error.
    How should I resolve this problem?

    Thanks
    Last edited by smshamim; 30th August 2006 at 13:16.

Similar Threads

  1. QDirModel - show directory ".."?
    By jamd in forum Qt Programming
    Replies: 3
    Last Post: 23rd April 2009, 19:51
  2. create file in another directory
    By raphaelf in forum Qt Programming
    Replies: 3
    Last Post: 16th February 2006, 10:04
  3. Am I the only one with "make" error ?
    By probine in forum Installation and Deployment
    Replies: 1
    Last Post: 13th February 2006, 12:54
  4. saving into a directory
    By Bahar in forum Qt Programming
    Replies: 5
    Last Post: 7th February 2006, 16:19
  5. QT Service and working directory
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 11:46

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.