Results 1 to 4 of 4

Thread: Slow FTP Program using QFtp

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

    Default Slow FTP Program using QFtp

    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 Weeks

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Slow FTP Program using QFtp

    Quote Originally Posted by neveffects View Post
    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.
    Without seeing any implementation details or any code it is very difficult to answer.

    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 Weeks
    If you want other tools, you first need to define which ones you already tried.
    As far as for memory leak detection in Qt4.7, I think there isn't any.

    You can use the standard tools like a debugger or tracer. Valgrind is popular.

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

    Default Re: Slow FTP Program using QFtp

    Below I am attaching my full working code. Here in main.cpp i am creating maximum 10 threads for ten machines . Now I ll start the threads soon after its creation. then inside the FileMonitoring.cpp which inherits the QTimer base class so after a particular time interval this FileMonitoring Class is called, inside which the checking of files inside an Outbox folder is happening. This FileMonitoring class is called from main.cpp inside which the Timer will emit a timeout signal every 6000 mSec. Now inside TransferThread.cpp file another timer will emit a timeout signal after every 500 mSec. in this timeOut slot connecting FTP and sending file is happening. While transfering data dataTransferProgress signal is working and after sending a particular size of the file or group of bits it will stop emitting this signal and an endless while loop will occur inside the TransferThread::run() method's else loop.
    Qt Code:
    1. ============TransferThread.cpp================
    2. TransferThread::TransferThread(QString ThreadName) : QThread(0) {
    3. stopFlag = false;
    4. _name = ThreadName;
    5. _userName = "administrator";
    6. _password = "admin";
    7. port = 9012;
    8. connectingDB();
    9. }
    10.  
    11. void TransferThread::initFTP() {
    12. ftp = new QFtp(this);
    13. QTimer *loginTimer=new QTimer();
    14. loginTimer->start(500);
    15. connect(loginTimer,SIGNAL(timeout()),this,SLOT(loginFTP()));
    16. connect(ftp, SIGNAL(commandFinished(int,bool)),this,SLOT(commandFinished(int,bool)));
    17. connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),this,SLOT(dataTransferProgress(qint64,qint64)));
    18. connect(ftp, SIGNAL(stateChanged(int)),this,SLOT(stateChanged(int)));
    19. }
    20. void TransferThread::loginFTP() {
    21. if((ftp->state()==QFtp::Unconnected || ftp->state()==QFtp::Closing) ) {
    22. this->terminate();
    23. ftp->abort();
    24. if(_checkingHostName==_hostName) {
    25. _checkingHostName = _alternateHostName;
    26. } else {
    27. _checkingHostName = _hostName;
    28. }
    29. ftp -> connectToHost(_checkingHostName,port);
    30. ftp -> login(_userName, _password);
    31. }
    32. if(ftp -> state() == QFtp::LoggedIn) {
    33. this->start();
    34. }
    35. }
    36. void TransferThread::run() {
    37. complete=0;
    38. f_done=0;
    39. f_total=0;
    40. while(!stopFlag) {
    41. if(complete==0) {
    42. if(fileSelection(branchName)) {
    43. fileSendProcess();
    44. }
    45. } else {
    46. qWarning() << "ENDLESS LOOP NOT STOPPING"
    47. }
    48. sleep(2);
    49. }
    50. }
    51. void TransferThread::fileSendProcess() {
    52. if(sendFileProcess() ) {
    53. QMutex *mut=new QMutex();
    54. mut->lock();
    55. sendDataFTP(_filename);
    56. mut->unlock();
    57. }
    58. }
    59. void TransferThread::sendDataFTP(QString fileName) {
    60. Process *proc = new Process();
    61. QString file="../"+_destination+"/outbox/"+fileName;
    62. QFile *filetrans= new QFile(file);
    63. if(filetrans->exists()) {
    64. if ( !filetrans->open( IO_ReadOnly ) ) {
    65. unsendFileProcess(fileName, "Cannot Open File");
    66. proc->process("mv "+fileName+" ../files_unsent", "FILE MOVING TO UNSEND FOLDER");
    67. filetrans = NULL;
    68. proc->close();
    69. filetrans->close();
    70. proc = NULL;
    71. delete proc;
    72. delete filetrans;
    73. return;
    74. }
    75. } else {
    76. filetrans = NULL;
    77. proc->close();
    78. proc = NULL;
    79. delete proc;
    80. delete filetrans;
    81. return ;
    82. }
    83. QSqlQuery qry;
    84. qry.exec("insert into filessending values('"+_filename+"','"+_destination+"');");
    85. QByteArray buffer;
    86. QMutex *mut_buffer=new QMutex();
    87. mut_buffer->lock();
    88. buffer = filetrans->readAll();
    89. mut_buffer->unlock();
    90. ftp->put(buffer,fileName,QFtp::Binary);
    91. complete=1;
    92. proc->close();
    93. proc = NULL;
    94. delete filetrans;
    95. delete proc;
    96. }
    97. void TransferThread::dataTransferProgress(qint64 done, qint64 total)
    98. {
    99. Process *proc = new Process();
    100. QSqlQuery qryUpdate;
    101. QSqlQuery query;
    102. QString pbid;
    103. QString brid;
    104. QString fileName=_filename;
    105. pbid=publisherId(_filename.mid(0,2));
    106. brid=branchId(_destination);
    107. str_pbId=pbid;
    108. str_brId=brid;
    109. QString strUpdate = "update transferstatus set "
    110. " done = "+QString::number(done)+","
    111. " total="+QString::number(total)+","
    112. " pb_id="+pbid+
    113. " where filename='"+_filename+"' and br_id="+_destinationId+"";
    114. qryUpdate.exec(strUpdate);
    115. sendFileSize = done;
    116. int count=0;
    117. while(sendFileSize>1024) {
    118. count++;
    119. sendFileSize=sendFileSize/1024;
    120. }
    121. f_total=total;
    122. f_done=done;
    123. if(done==total) {
    124. qryUpdate.exec("delete from filessending where filename='"+_filename+"' and destination='"+_destination+"';");
    125. qryUpdate.exec("delete from file_transfer_queue where filename='"+_filename+"' and br_id="+brid+" and pb_id="+pbid+";");
    126. QTime now;
    127. QString csq;
    128. QTime strtTime;
    129. QString duration=getDuration(strtTime,now);
    130. QString timecurrent=QTime::currentTime ().toString(Qt::TextDate);
    131. strtTime=strtTime.fromString(_timestart, Qt::TextDate);
    132. now=now.fromString( timecurrent,Qt::TextDate );
    133. csq="insert into transreport(file, size, dot, start,"
    134. " finish, br_id, pb_id, duration,rid)values('"+_alias+
    135. "','"+_fileSize+"','"+QDate::currentDate ().toString()+
    136. "','"+_starttime+"','"+QTime::currentTime ().toString("hh:mm:ss ap")+
    137. "',"+brid+","+pbid+",'"+duration+"',"+_releaseid+");";
    138. query.exec(csq);
    139. int count=1;
    140. while(checkingSendFile(fileName)) {
    141. fileName.append(QString::number(count));
    142. count++;
    143. }
    144. proc->process("mv ../"+_destination+"/outbox/"+fileName + " ../sentfiles/", "MOVING FILE TO SEND FOLDER");
    145. complete=0;
    146. } else {
    147. QSqlQuery queryselect;
    148. QString selectqry="select status from transferstatus"
    149. " where filename='"+_alias+
    150. "' and br_id="+brid+" and pb_id="+pbid+";";
    151. queryselect.exec(selectqry);
    152. if(queryselect.next()) {
    153. QString statusfile=queryselect.value(0).toString();
    154. if(statusfile.compare("stop")==0) {
    155. ftp->abort();
    156. unsendFileProcess(_filename, "Transfer Cancelled");
    157. proc->process("mv ../"+_destination+"/outbox/"+_filename+" ../files_unsent","MOVING FILES FROM BRANCH _ OUTBOX TO FILES UNSENT");
    158. QSqlQuery qry2;
    159. qry2.exec("delete from filessending where filename='"+_filename+"' and destination='"+_destination+"';");
    160. }
    161. }
    162. }
    163. proc->close();
    164. proc = NULL;
    165. delete proc;
    166. }
    167. =======================FileMonitoring.cpp===================
    168. FileMonitoring::FileMonitoring() : QTimer(0)
    169. {
    170. connect(this,SIGNAL(timeout()),this,SLOT(timeout()));
    171. }
    172. void FileMonitoring::timeout()
    173. {
    174. QDir *qd=new QDir();
    175. QStringList stringList;
    176. bool flag = true;
    177. qd->refresh();
    178. qd->setCurrent("../outbox");
    179. stringList=qd->entryList(QDir::Files,QDir::Time);
    180. stop();
    181. for (int index = 0; index < stringList.size(); ++index) {
    182. QFileInfo fileInfo=QFileInfo(stringList.at(index));
    183. QDateTime modtime=fileInfo.lastRead();
    184. flag = patternCheck(fileInfo.fileName()); //PATTERN CHECKING
    185. if(flag) {
    186. int filestay=modtime.secsTo(QDateTime::currentDateTime());
    187. if(filestay>=20) {
    188. flag = checkingFile(fileInfo);
    189. if(flag) {
    190. flag = branchExtract(fileInfo);
    191. }
    192. }
    193. } else {
    194. Process *pro=new Process();
    195. unsendFileProcess(fileInfo.fileName(), "Pattern Mismatch!");
    196. pro->process("mv "+fileInfo.fileName()+" ../files_unsent", "FILE MOVING TO UNSEND FOLDER");
    197. pro->close();
    198. pro = NULL;
    199. delete pro;
    200. }
    201. }
    202. delete qd;
    203. start(interval());
    204. }
    205. ==================main.cpp========================
    206. int main(int argc, char *argv[]) {
    207. QApplication a(argc,argv);
    208. connectingDB();
    209. fileTransfer();
    210. startProcessThread();
    211. return a.exec();
    212. }
    213. void fileTransfer() {
    214. FileMonitoring *objMonitor=new FileMonitoring();
    215. objMonitor->start(6000);
    216. }
    217. void startProcessThread() {
    218. QSqlQuery query;
    219. query.exec(" select br_id, "
    220. " br_code, "
    221. " br_name, "
    222. " ipaddress, "
    223. " alt_ipaddress "
    224. " from branch"
    225. //" where br_id in(42)"
    226. " order by br_name;");
    227. int index = 0;
    228. while(query.next() && index<10) {
    229. QString threadName = "THREAD_" + query.value(0).toString()
    230. + "_" + query.value(1).toString()
    231. + "_" + query.value(2).toString();
    232. QString ipaddress=query.value(3).toString();
    233. QString alternateIpaddress=query.value(4).toString();
    234. QString branchName=query.value(2).toString();
    235. thread[index]=new TransferThread(threadName);
    236. thread[index]->setBranch(branchName);
    237. thread[index]->setAlternateHostName(alternateIpaddress);
    238. thread[index]->setHostName(ipaddress);
    239. thread[index]->initFTP();
    240. index++;
    241. }
    242. totalThread=index+1;
    243. }
    244. }
    245. =============Process.cpp====================
    246. Process::Process() : QProcess(0) {
    247. bool Process::process(QString process, QString message) {
    248. _processCommand=process;
    249. _processMessage=message;
    250. start(process);
    251. if(!waitForStarted()) {
    252. return false;
    253. }
    254. if(!waitForFinished()) {
    255. return false;
    256. }
    257. return true;
    258. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Slow FTP Program using QFtp

    Finally I have got the Solution for my problem. I have rechecked all the code and finally I found out that , while we are accessing any database inside the thread then use the connection created inside the thread itself. Donot use the default connection which may opened inside the main function. So that was the problem for the slow process of QFtp.

    Thank you

Similar Threads

  1. QFtp sample program
    By comlink21 in forum Qt Programming
    Replies: 7
    Last Post: 27th April 2012, 08:59
  2. Replies: 1
    Last Post: 30th April 2010, 13:25
  3. Replies: 7
    Last Post: 19th January 2008, 15:29
  4. Replies: 0
    Last Post: 23rd September 2007, 11:54
  5. Replies: 1
    Last Post: 20th January 2006, 12:01

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.