PDA

View Full Version : FTP Program using multiple Threads



neveffects
2nd December 2010, 11:39
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:


mutex->lock();
ftp->connectToHost (route,9012);
ftp->login ("administrator","admin");

connect(ftp,SIGNAL(stateChanged(int)),this,SLOT(St atus(int)));
connect(ftp,SIGNAL(dataTransferProgress(int,int)), this,SLOT(UpdateProgress(int,int)));
ftp->put( filetrans,aliasname);
mutex->unlock();

Please Help me.

Thanks in advance.

TorAn
2nd December 2010, 13:28
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...)

neveffects
3rd December 2010, 04:55
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:


mutex->lock();
qWarning("AFTER MUTEX LOCK");

ftp->connectToHost (route,9012);
qApp->processEvents();
qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
ftp->login ("administrator","admin");
qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
connect(ftp,SIGNAL(stateChanged(int)),this,SLOT(St atus(int)));

connect(ftp,SIGNAL(dataTransferProgress(int,int)), this,SLOT(UpdateProgress(int,int)));
qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox");
qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
ftp->put( filetrans,aliasname);
qWarning("######################################## ##CURRENT COMMAND::::"+ftp->currentCommand ());
qWarning("BEFORE MUTEX UNLOCK");
mutex->unlock();


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.

ChrisW67
3rd December 2010, 07:05
ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox")

This looks like it is almost certainly not a valid path. Does your remote path really look like this? (All quotes are single quotes)


C:''Administrator Documents and Settings''Administrator''Desktop''Inbox


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

neveffects
3rd December 2010, 09:17
ftp->cd("C:'\'Administrator Documents and Settings'\'Administrator'\'Desktop'\'Inbox")

This looks like it is almost certainly not a valid path. Does your remote path really look like this? (All quotes are single quotes)


C:''Administrator Documents and Settings''Administrator''Desktop''Inbox


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
ftp->cd("C:\Documents and Settings\Administrator\Desktop\Inbox");

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.

neveffects
3rd January 2011, 05:33
I have got the solution. The problem was with my


ftp->put(QIODevice,fileName);

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


QFile *filetrans =new QFile(fileName);
QByteArray buffer;
buffer = filetrans->readAll();
ftp->put(buffer,fileName,QFtp::Binary);

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