Results 1 to 6 of 6

Thread: FTP Program using multiple Threads

  1. #1
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default FTP Program using multiple Threads

    Hello Everyone,

    I am facing a problem in using the QFtp class in QT4.7.0 and my Qt creator is 2.0.1 I am trying to send one file to another machine using QFtp. I am trying this within multipe threads. I have tried in a single thread , then also it is not connecting or sending any file.

    My code is attaching here:

    Qt Code:
    1. mutex->lock();
    2. ftp->connectToHost (route,9012);
    3. ftp->login ("administrator","admin");
    4.  
    5. connect(ftp,SIGNAL(stateChanged(int)),this,SLOT(Status(int)));
    6. connect(ftp,SIGNAL(dataTransferProgress(int,int)),this,SLOT(UpdateProgress(int,int)));
    7. ftp->put( filetrans,aliasname);
    8. mutex->unlock();
    To copy to clipboard, switch view to plain text mode 

    Please Help me.

    Thanks in advance.
    Last edited by wysota; 3rd December 2010 at 09:48. Reason: missing [code] tags

  2. #2
    Join Date
    Nov 2009
    Location
    US, Midwest
    Posts
    215
    Thanks
    62
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: FTP Program using multiple Threads

    Can you ftp to the remote root directory using any of the ftp clients? (my code is similar to yours in respect to ftp, but I do ftp->cd ("remotedir") and only then ftp->put...)

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

    neveffects (3rd December 2010)

  4. #3
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: FTP Program using multiple Threads

    Quote Originally Posted by TorAn View Post
    Can you ftp to the remote root directory using any of the ftp clients? (my code is similar to yours in respect to ftp, but I do ftp->cd ("remotedir") and only then ftp->put...)
    Hi ,
    I have tried giving ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox") before the ftp->put(.. then also the same effect.
    Now I tried giving like this:

    Qt Code:
    1. mutex->lock();
    2. qWarning("AFTER MUTEX LOCK");
    3.  
    4. ftp->connectToHost (route,9012);
    5. qApp->processEvents();
    6. qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
    7. ftp->login ("administrator","admin");
    8. qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
    9. connect(ftp,SIGNAL(stateChanged(int)),this,SLOT(St atus(int)));
    10.  
    11. connect(ftp,SIGNAL(dataTransferProgress(int,int)), this,SLOT(UpdateProgress(int,int)));
    12. qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
    13. ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox");
    14. qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
    15. ftp->put( filetrans,aliasname);
    16. qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
    17. qWarning("BEFORE MUTEX UNLOCK");
    18. mutex->unlock();
    To copy to clipboard, switch view to plain text mode 

    Here the current command is not showing anything.
    the above code is working inside a single thread.

    also those signals are not emitting . any more options should i include?

    please help me.

    Thanks in advance.
    Last edited by wysota; 3rd December 2010 at 09:49. Reason: missing [code] tags

  5. #4
    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: FTP Program using multiple Threads

    Qt Code:
    1. ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox")
    To copy to clipboard, switch view to plain text mode 
    This looks like it is almost certainly not a valid path. Does your remote path really look like this? (All quotes are single quotes)
    Qt Code:
    1. C:''Administrator Documents and Settings''Administrator''Desktop''Inbox
    To copy to clipboard, switch view to plain text mode 

    Also, all the commands you have issued will be queued and will not execute until your program returns to its event loop.

  6. #5
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: FTP Program using multiple Threads

    Quote Originally Posted by ChrisW67 View Post
    Qt Code:
    1. ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox")
    To copy to clipboard, switch view to plain text mode 
    This looks like it is almost certainly not a valid path. Does your remote path really look like this? (All quotes are single quotes)
    Qt Code:
    1. C:''Administrator Documents and Settings''Administrator''Desktop''Inbox
    To copy to clipboard, switch view to plain text mode 

    Also, all the commands you have issued will be queued and will not execute until your program returns to its event loop.

    I have tried
    Qt Code:
    1. ftp->cd("C:\Documents and Settings\Administrator\Desktop\Inbox");
    To copy to clipboard, switch view to plain text mode 

    this is the exact path in my program.

    I am trying to connect to a windows machine is there any need of other parameters for ftp?
    In Qt3 the same program is working fine with 9 threads. But in Qt4 it is not working in a single thread itself.

    Please help me .
    Thanks in advance.
    Last edited by wysota; 3rd December 2010 at 09:49. Reason: missing [code] tags

  7. #6
    Join Date
    Dec 2009
    Posts
    9
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: FTP Program using multiple Threads

    I have got the solution. The problem was with my

    Qt Code:
    1. ftp->put(QIODevice,fileName);
    To copy to clipboard, switch view to plain text mode 

    If QIODevice is used then only commandFinished signal will be emitting. To emit datatransferProgress we should use QByteArray like this:

    Qt Code:
    1. QFile *filetrans =new QFile(fileName);
    2. QByteArray buffer;
    3. buffer = filetrans->readAll();
    4. ftp->put(buffer,fileName,QFtp::Binary);
    To copy to clipboard, switch view to plain text mode 


    Added after 16 minutes:


    Now I am facing another problem:

    I am trying to upload 2 files to one machine and another 3 files to another machine using my FTP program. In this situation we have two threads running at a time for the two machine. This threads will check a folder named outbox in a particular time interval using the QTimer for any files to be uploaded. User will continuously copy files to be uploaded into the Outbox folder at irregular time intervals. For two or three times the file uploading will complete successfully. After that the datatransfer will slow down gradually and finally it will work endless without any progress in datatransfer. For monitoring the transfer progress I have connected the dataTransferProgress Signal. I am using many pointers and Objects and also I am deleting the pointer objects after its usage. Is there any other debugging methods for memory leak in Qt4.7 Please help me. I am trying it for 2 Months

    Thanks in advance
    Last edited by neveffects; 3rd January 2011 at 05:33.

Similar Threads

  1. Server with multiple clients without threads
    By kernel.roy in forum Newbie
    Replies: 2
    Last Post: 9th September 2010, 04:53
  2. Multiple threads with one QTcpSocket
    By xenome in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2010, 20:20
  3. Phonon on multiple threads
    By Savignon in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2009, 22:17
  4. Waiting for multiple threads
    By Bebee in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2008, 17:21
  5. Organizing multiple threads
    By vratojr in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2006, 09:53

Tags for this Thread

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.