hiii,
as per ur reply i tried. program works normally even it downloads the directories and files but no contents are downloaded only empty folders are stored. in my program file supri.c which is readable is downloaded as supri.c empty folder no contents. am not getting why this is happening???
also after running it gives error as

Starting /home/supriya/FinalYr_Prjct/abc/abc...
Error: Changing directory failed:
Failed to change directory.
/home/supriya/FinalYr_Prjct/abc/abc exited with code 0

what is this error and how to remove?? plz help me out...

source code:
Qt Code:
  1. ------------main.c--------------
  2. #include <QtGui/QApplication>
  3. #include <iostream>
  4. #include "client.h"
  5.  
  6. using namespace std;
  7.  
  8.  
  9. /*int main(int argc, char *argv[])
  10. {
  11.   QApplication a(argc, argv);
  12.   client w;
  13.   w.show();
  14.   return a.exec();
  15. }*/
  16.  
  17.  
  18. int main(int argc, char *argv[])
  19. {
  20. argc = 2;
  21. //*argv ="ftp://qt.nokia.com";
  22. QCoreApplication app(argc, argv);
  23. QStringList args = app.arguments();
  24. if (args.count() != 2) {
  25. cerr << "Usage: spider url" << endl
  26. << "Example:" << endl
  27. << "spider ftp://ftp.trolltech.com/freebies/leafnode"<< endl;
  28. return 1;
  29. }
  30.  
  31. Spider spider;
  32. if (!spider.getDirectory(QUrl("ftp://localhost/supriya/supri.c")))
  33. return 1;
  34. QObject::connect(&spider, SIGNAL(done()), &app, SLOT(quit()));
  35. return app.exec();
  36. }
  37.  
  38. -----------------client.cpp-------------
  39.  
  40. #include "client.h"
  41. #include <iostream>
  42. using namespace std;
  43. client::client(QWidget *parent)
  44. : QWidget(parent)
  45. {
  46.  
  47. }
  48. client::~client()
  49. {
  50.  
  51. }
  52.  
  53. Spider::Spider(QObject *parent)
  54. : QObject(parent)
  55. {
  56. connect(&ftp, SIGNAL(done(bool)), this, SLOT(ftpDone(bool)));
  57. connect(&ftp, SIGNAL(listInfo(const QUrlInfo &)),
  58. this, SLOT(ftpListInfo(const QUrlInfo &)));
  59. }
  60.  
  61. bool Spider::getDirectory(const QUrl &url)
  62. {
  63. if (!url.isValid()) {
  64. cerr << "Error: Invalid URL" << endl;
  65. return false;
  66. }
  67.  
  68. if (url.scheme() != "ftp") {
  69. cerr << "Error: URL must start with ’ftp:’" << endl;
  70. return false;
  71. }
  72.  
  73. ftp.connectToHost(url.host(), url.port(21));
  74. ftp.login(tr("supriya"),tr("supriya"));
  75. QString path = url.path();
  76. if (path.isEmpty())
  77. path = "/";
  78. pendingDirs.append(path);
  79. processNextDirectory();
  80. return true;
  81. }
  82.  
  83. void Spider::processNextDirectory()
  84. {
  85. if(!pendingDirs.isEmpty()) {
  86.  
  87. currentDir = pendingDirs.takeFirst();
  88. currentLocalDir = "downloads/" + currentDir;
  89. QDir(".").mkpath(currentLocalDir);
  90. ftp.cd(currentDir);
  91. ftp.list(currentDir);
  92. }else
  93. emit done();
  94.  
  95. }
  96.  
  97.  
  98. void Spider::ftpListInfo(const QUrlInfo &urlInfo)
  99. {
  100. cout << "list info"<< endl;
  101. if (urlInfo.isFile()) {
  102. if (urlInfo.isReadable()) {
  103. QFile *file = new QFile(currentLocalDir + "/"+ urlInfo.name());
  104. if (!file->open(QIODevice::WriteOnly)) {
  105. cerr << "Warning: Cannot open file "
  106. << qPrintable(
  107.  
  108. QDir::convertSeparators(file->fileName()))
  109. << endl;
  110. return;
  111. }
  112. ftp.get(urlInfo.name(), file);
  113. openedFiles.append(file);
  114. }
  115. } else if (urlInfo.isDir() && !urlInfo.isSymLink()) {
  116. pendingDirs.append(currentDir + "/" + urlInfo.name());
  117. }
  118. }
  119.  
  120. void Spider::ftpDone(bool error)
  121. {
  122.  
  123. if (error) {
  124. cerr << "Error: " << qPrintable(ftp.errorString()) << endl;
  125. } else {
  126. cout << "Downloaded " << qPrintable(currentDir) << " to "<<
  127. qPrintable(QDir::convertSeparators(QDir(currentLocalDir).canonicalPath()));
  128. }
  129. qDeleteAll(openedFiles);
  130. openedFiles.clear();
  131. processNextDirectory();
  132. }
  133.  
  134. -----------------------client.h-----------------------
  135.  
  136. #ifndef CLIENT_H
  137. #define CLIENT_H
  138. #include <QUrl>
  139. #include <QtGui/QWidget>
  140. #include <QUrlInfo>
  141. #include <QFtp>
  142. #include <QFile>
  143. #include <QDir>
  144. class client : public QWidget
  145. {
  146. Q_OBJECT
  147.  
  148. public:
  149. client(QWidget *parent = 0);
  150. ~client();
  151. };
  152.  
  153. class Spider : public QObject
  154. {
  155. Q_OBJECT
  156. public:
  157. Spider(QObject *parent = 0);
  158. bool getDirectory(const QUrl &url);
  159. signals:
  160. void done();
  161. private slots:
  162. void ftpDone(bool error);
  163. void ftpListInfo(const QUrlInfo &urlInfo);
  164. private:
  165. void processNextDirectory();
  166.  
  167. QFtp ftp;
  168. QList<QFile *> openedFiles;
  169. QString currentDir;
  170. QString currentLocalDir;
  171. QStringList pendingDirs;
  172.  
  173. };
  174.  
  175. #endif // CLIENT_H
To copy to clipboard, switch view to plain text mode