Hi guys,

I am working on an FTP Client that is searching in the current directory for other directories.
When he founds some, he will try to download 2 special files inside these directories.

My problem is, the client is doing well as far as hes choosing the right folders, creating them and also trying to get all the files.

But somewhere, I dont know where he stops downloading the files.
So some Files that were queued wont download and the rest of the files were almost loaded but only almost (~5 kbyte are still missing).

I have no Idea where my mistake could be.

Sorry for my english, i am from Germany.
Can you pls have a look at my source Code? Its just an fragment of my whole program.

header
Qt Code:
  1. #ifndef FTPCONNECT_H
  2. #define FTPCONNECT_H
  3.  
  4. #include <QtGui>
  5. #include <QtNetwork>
  6. #include <QByteArray>
  7. #include <QtGui/QMainWindow>
  8.  
  9. #include "deviceroutine.h"
  10.  
  11. using namespace std;
  12.  
  13. class FTPconnect : DeviceRoutine
  14. {
  15. Q_OBJECT
  16. public:
  17. FTPconnect(Ui::DeviceRoutineClass *,QWidget *parent = 0, Qt::WFlags flags = 0);
  18. ~FTPconnect();
  19.  
  20. QProgressDialog *progress;
  21. QFtp *ftpzeiger;
  22. QFile *file;
  23. bool abgebrochen;
  24.  
  25. private:
  26. //Zeiger auf die UI der DeviceRoutine
  27. Ui::DeviceRoutineClass* ui;
  28. //Array für alle Verzeichnisse des FTP
  29. vector <QString> directorylist;
  30. int dircount;
  31.  
  32. public slots:
  33. void ftp_start();
  34. void ftp_ende();
  35. void ftp_progress(qint64 done,qint64 total);
  36. void ftp_CommandFinished(int, bool error);
  37. void ftp_CommandStarted(int id);
  38. void ftp_abort();
  39.  
  40. void getfiles(const QUrlInfo &);
  41. void getdirectories(const QUrlInfo &);
  42. void getdirectories_ende();
  43. };
  44.  
  45. #endif
To copy to clipboard, switch view to plain text mode 

... cpp
Qt Code:
  1. #include "FTPconnect.h"
  2. #include "deviceroutine.h"
  3. #include <QMessageBox>
  4.  
  5. FTPconnect::FTPconnect(Ui::DeviceRoutineClass *ui,QWidget *parent, Qt::WFlags flags) : DeviceRoutine(parent, flags){
  6.  
  7. //Zeiger auf UI setzen
  8. this->ui=ui;
  9. file=NULL;
  10. dircount=0;
  11. }
  12.  
  13. FTPconnect::~FTPconnect(){}
  14.  
  15. void FTPconnect::ftp_start(){
  16.  
  17. ui->textEdit_ausgabe_FTP->setText("");
  18.  
  19. abgebrochen=false;
  20.  
  21. if((is_directory(ui->lineEdit_FTP_pfad->text().toStdString())==0) && (ui->lineEdit_FTP_pfad->isEnabled()==1)){
  22. //Dann breche die Aktion ab und wähle neuen Pfad
  23. ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n") ;
  24. ui->textEdit_ausgabe_FTP->append("Kein gueltiger FTP Ausgabepfad angegeben! Bitte aendern...\n");
  25. ui->textEdit_ausgabe_FTP->append("------------------------------------------------------------------------------------\n");
  26. //wähle neuen Pfad
  27. return;
  28. }
  29.  
  30. progress= new QProgressDialog("Analysiere Verzeichnisstruktur...", "Abbrechen", 0, 100, this);
  31. progress->setAutoReset(0);
  32.  
  33. //Ftp bereistellen
  34. ftpzeiger = new QFtp();
  35. ftpzeiger->setTransferMode(QFtp::Active);
  36.  
  37. connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
  38. connect(ftpzeiger, SIGNAL(dataTransferProgress(qint64, qint64)), this, SLOT(ftp_progress(qint64,qint64)));
  39. connect(ftpzeiger, SIGNAL(commandStarted(int)),this, SLOT(ftp_CommandStarted(int)));
  40. connect(ftpzeiger, SIGNAL(commandFinished(int,bool)),this, SLOT(ftp_CommandFinished(int,bool)));
  41.  
  42. //Hole nur Verzeichnisse
  43. connect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getdirectories(QUrlInfo)));
  44.  
  45. //Host aus dem Lineedit holen
  46. this->ftpzeiger->connectToHost(ui->lineEdit_host->text());
  47.  
  48. //Logindaten - Wenn beide Felder leer --> anonymous Login
  49. if ((ui->lineEdit_login->text())=="" && (ui->lineEdit_passwort->text()==""))
  50. ftpzeiger->login();
  51. else
  52. ftpzeiger->login(ui->lineEdit_login->text(),ui->lineEdit_passwort->text());
  53.  
  54. if (ui->lineEdit_verzeichnis->text()==0){
  55. ui->textEdit_ausgabe_FTP->append("Bitte ein Verzeichnis angeben...");
  56. this->~FTPconnect();
  57. return;
  58. }
  59. //Verzeichnis auswählen
  60. ftpzeiger->cd(ui->lineEdit_verzeichnis->text());
  61.  
  62. //Directory Listing
  63. ftpzeiger->list();
  64. //Event Schleife
  65. progress->exec();
  66.  
  67. if(directorylist.size()==0)
  68. ui->textEdit_ausgabe_FTP->append("Keine gueltigen Dateien gefunden...\n");
  69.  
  70. //Events für Ende und Datenübertragung
  71. connect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(ftp_ende()));
  72.  
  73.  
  74. //Trenne nicht mehr benötigte Signale
  75. disconnect(ftpzeiger, SIGNAL(done(bool)), this, SLOT(getdirectories_ende()));
  76. disconnect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getdirectories(QUrlInfo)));
  77.  
  78. //Hole nur noch Dateien
  79. connect(ftpzeiger, SIGNAL(listInfo(QUrlInfo)),this, SLOT(getfiles(QUrlInfo)));
  80.  
  81. //Für jede gefundenen Ordner
  82. for(dircount=0;dircount<directorylist.size();dircount++){
  83. progress= new QProgressDialog("Kopiere Dateien...", "Abbrechen", 0, 100, this);
  84. //connect(progress, SIGNAL(canceled()), this, SLOT(ftp_abort()));
  85.  
  86. //Verzeichnis und File auswählen
  87. ftpzeiger->cd(ui->lineEdit_verzeichnis->text() + "/" + directorylist[dircount]);
  88.  
  89. //Dateien werden gesucht - intern
  90. ftpzeiger->list();
  91.  
  92. ui->textEdit_ausgabe_FTP->append("Verzeichnis:" + directorylist[dircount]);
  93. progress->exec();
  94. }
  95. }
  96.  
  97. void FTPconnect::ftp_ende(){
  98. if (abgebrochen==1){
  99. ui->textEdit_ausgabe_FTP->append("\nDownload abgebrochen!");
  100. }
  101. if(ftpzeiger->error()==0)
  102. ui->textEdit_ausgabe_FTP->append("Datei erfolgreich heruntergeladen!");
  103. else
  104. ui->textEdit_ausgabe_FTP->append(this->ftpzeiger->errorString());
  105.  
  106. //Aufräumen
  107. this->progress->close();
  108. this->progress->deleteLater();
  109. this->progress=NULL;
  110. }
  111.  
  112. //setze DL Fortschritt in Progressbar um
  113. void FTPconnect::ftp_progress(qint64 done,qint64 total){
  114. this->progress->setMaximum(total);
  115. this->progress->setValue(done);
  116. }
  117.  
  118. void FTPconnect::ftp_CommandFinished(int, bool error){
  119.  
  120. if (ftpzeiger->currentCommand() == QFtp::ConnectToHost) {
  121. ui->textEdit_ausgabe_FTP->append("Verbindung zum Host aufgebaut...\n");
  122. if (error){
  123. ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
  124. this->progress->close();
  125. }
  126. }
  127.  
  128. if (ftpzeiger->currentCommand() == QFtp::Login){
  129. ui->textEdit_ausgabe_FTP->append("Logindaten ueberprüft...\n");
  130. if (error){
  131. ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
  132. this->progress->close();
  133. }
  134. }
  135.  
  136. if (ftpzeiger->currentCommand() == QFtp::Get) {
  137.  
  138. ui->textEdit_ausgabe_FTP->append("Datenuebertragung beendet...\n");
  139. if (error) {
  140. ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
  141. ftpzeiger->abort();
  142. this->progress->close();
  143. file->close();
  144. file->remove();
  145. }
  146. }
  147.  
  148. if (ftpzeiger->currentCommand() == QFtp::List) {
  149. ui->textEdit_ausgabe_FTP->append("Verzeichnisse eingelesen...\n");
  150. if (error) {
  151. ui->textEdit_ausgabe_FTP->append(ftpzeiger->errorString ());
  152. ftpzeiger->abort();
  153. this->progress->close();
  154. }
  155. }
  156. }
  157.  
  158. void FTPconnect::ftp_CommandStarted(int id){
  159.  
  160. if (ftpzeiger->currentCommand() == QFtp::ConnectToHost)
  161. ui->textEdit_ausgabe_FTP->append("Verbindung zum Host wird aufgebaut...");
  162.  
  163. if (ftpzeiger->currentCommand() == QFtp::Login)
  164. ui->textEdit_ausgabe_FTP->append("Logindaten werden ueberprüft...");
  165.  
  166. if (ftpzeiger->currentCommand() == QFtp::Get)
  167. ui->textEdit_ausgabe_FTP->append("Datenuebertragung gestartet...");
  168.  
  169. if (ftpzeiger->currentCommand() == QFtp::List)
  170. ui->textEdit_ausgabe_FTP->append("Lese Verzeichniss ein...");
  171. }
  172.  
  173. void FTPconnect::ftp_abort(){
  174. this->ftpzeiger->abort();
  175. this->progress->close();
  176. abgebrochen=1;
  177.  
  178. }
  179.  
  180. void FTPconnect::getfiles(const QUrlInfo &urlInfo){
  181. //Wenn devlist oder devparm ist
  182. if ((urlInfo.isDir()==false) && ((urlInfo.name()=="devList.dat") || (urlInfo.name()=="devParm.dat"))){
  183.  
  184. if (ui->radioButton_FTP_eigen->isChecked()){
  185. //Wenn der Rezeptordner nicht existiert,lege ihn an
  186. if(is_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString())==false)
  187. create_directory(ui->lineEdit_FTP_pfad->text().toStdString() + "\\" + directorylist[dircount].toStdString());
  188.  
  189. progress->setLabelText("Downloade " + directorylist[dircount] + "...");
  190. ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
  191.  
  192. //File zum schreiben/lesen öffnen
  193. file = new QFile(ui->lineEdit_FTP_pfad->text() + "\\" + directorylist[dircount] + "\\" + urlInfo.name() );
  194. file->open(QIODevice::WriteOnly);
  195.  
  196. ftpzeiger->get(urlInfo.name(),file);
  197. }
  198. //Standartausgabe nach FTP
  199. else{
  200. //Wenn FTP noch nicht existiert, lege es an
  201. if(is_directory("FTP")==false)
  202. create_directory("FTP");
  203.  
  204. //Wenn der Rezeptordner nicht existiert,lege ihn an
  205. if(is_directory("FTP\\" + directorylist[dircount].toStdString())==false)
  206. create_directory("FTP\\" + directorylist[dircount].toStdString());
  207.  
  208. progress->setLabelText("Downloade " + directorylist[dircount] + "...");
  209. ui->textEdit_ausgabe_FTP->append("Downloade " + urlInfo.name() + "...");
  210. /* Hier später auf DevList und DevParm prüfen */
  211.  
  212. //File zum schreiben/lesen öffnen
  213. file = new QFile("FTP\\" + directorylist[dircount] + "\\" + urlInfo.name() );
  214. file->open(QIODevice::ReadWrite);
  215.  
  216. ftpzeiger->get(urlInfo.name(),file);
  217.  
  218. }
  219. }
  220. }
  221.  
  222. void FTPconnect::getdirectories(const QUrlInfo &urlInfo){
  223.  
  224. //Wenn Verzeichnis ist (aber kein . oder ..)
  225. if ((urlInfo.isDir()==true) && (urlInfo.name()!=".") && (urlInfo.name()!=".."))
  226. directorylist.push_back(urlInfo.name());
  227. }
  228.  
  229. void FTPconnect::getdirectories_ende(){
  230.  
  231. //Aufräumen
  232. this->progress->close();
  233. this->progress=NULL;
  234.  
  235. }
To copy to clipboard, switch view to plain text mode 

Just ignore my German comments ...

I am happy if you could give me some other advices, still learning.


thx a lot,
c3po4