Results 1 to 11 of 11

Thread: QFtp...doesnt seems to work ....!!!

  1. #1
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QFtp...doesnt seems to work ....!!!

    hey guys....i have written this piece of code for a QFtp application,but this doesnt seem to work....i dont know whr it goes wrong,but it makes a file with 0 byte.......pls,pls any help wud be appreciated....

    Qt Code:
    1. /* main method */
    2.  
    3. #include <QtGui/QApplication>
    4. #include <QApplication>
    5. #include "exftp.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10. exFtp w;
    11.  
    12. w.show();
    13. //a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. /* .h File */
    2.  
    3. #ifndef EXFTP_H
    4. #define EXFTP_H
    5.  
    6. #include <QtGui/QMainWindow>
    7. #include <QFtp>
    8. #include <QUrl>
    9. #include <QFile>
    10. #include <QDialog>
    11. #include <QString>
    12. class QLineEdit;
    13. class QLabel;
    14. //#include "ui_exftp.h"
    15.  
    16. class exFtp : public QDialog
    17. {
    18. Q_OBJECT
    19.  
    20. public:
    21. exFtp();
    22. ~exFtp();
    23. private:
    24. QFtp *ftp;
    25. QFile file;
    26. QUrl *urlAdd;
    27. QString localFileName;
    28. QLineEdit *ftpServerLineEdit;
    29. QLabel *ftpServerLabel;
    30. QLabel *statusLabel;
    31. QPushButton *downloadButton;
    32. QPushButton *quitButton;
    33. QDialogButtonBox *buttonBox;
    34. QProgressDialog *progressDialog;
    35. //Ui::exFtpClass ui;
    36. private slots:
    37. bool downloadStarted();
    38. void EnabledButton(const QString&);
    39. void ftpDone(bool);
    40. void On_CommandFinished();
    41. };
    42.  
    43. #endif // EXFTP_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /* .cpp file */
    2.  
    3. #include <QtGui>
    4. #include "exftp.h"
    5.  
    6. exFtp::exFtp()
    7. {
    8. ftpServerLabel = new QLabel("FTP");
    9. ftpServerLineEdit = new QLineEdit();
    10. statusLabel = new QLabel();
    11. downloadButton = new QPushButton("Download");
    12. downloadButton->setEnabled(false);
    13. quitButton = new QPushButton("Quit");
    14. buttonBox = new QDialogButtonBox;
    15. buttonBox->addButton(downloadButton,QDialogButtonBox::ActionRole);
    16. buttonBox->addButton(quitButton,QDialogButtonBox::RejectRole);
    17. progressDialog = new QProgressDialog(this);
    18. QHBoxLayout *topLayout = new QHBoxLayout;
    19. topLayout->addWidget(ftpServerLabel);
    20. topLayout->addWidget(ftpServerLineEdit);
    21. QVBoxLayout *mainLayout = new QVBoxLayout;
    22. mainLayout->addLayout(topLayout);
    23. mainLayout->addWidget(statusLabel);
    24. mainLayout->addWidget(buttonBox);
    25. setLayout(mainLayout);
    26. ftp = new QFtp(this);
    27. connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(EnabledButton(const QString&)));
    28. // connect(ftpServerLineEdit,SIGNAL(textEdited(const QString&)),this,SLOT(QUrl(const QString&)))
    29. connect(downloadButton,SIGNAL(clicked()),this,SLOT(downloadStarted()));
    30. connect(ftp,SIGNAL(done(bool)),this,SLOT(ftpDone(bool)));
    31. connect(ftp,SIGNAL(commandFinished(int,bool)),this,SLOT(On_CommandFinished()));
    32. connect(quitButton,SIGNAL(clicked()),this,SLOT(accept()));
    33. //ui.setupUi(this);
    34. }
    35. void exFtp::EnabledButton(const QString& Url)
    36. {
    37. downloadButton->setEnabled(!(Url.isEmpty()));
    38. urlAdd = new QUrl();
    39. urlAdd->setUrl(Url);
    40. urlAdd->setPath(Url);
    41. QFileInfo fi(Url);
    42. localFileName = fi.fileName();
    43. if(localFileName.isEmpty())
    44. localFileName = "exFtp.out";
    45.  
    46. }
    47. void exFtp::On_CommandFinished()
    48. {
    49. file.close();
    50. }
    51. bool exFtp::downloadStarted()
    52. {
    53. file.setFileName(localFileName);
    54. //file.open(QIODevice::WriteOnly);
    55. if(!file.open(QIODevice::WriteOnly))
    56. {
    57. statusLabel->setEnabled(true);
    58. statusLabel->setText(tr("File at %1 cannot be Open/Accesed").arg(localFileName));
    59. return false;
    60. }
    61. ftp->connectToHost(urlAdd->host(),urlAdd->port(21));
    62. ftp->login();
    63. ftp->get(urlAdd->path(),&file);
    64. //ftp->close();
    65. return true;
    66. }
    67. void exFtp::ftpDone(bool fileDone)
    68. {
    69. if(fileDone)
    70. statusLabel->setText("DownLoaded");
    71. else
    72. statusLabel->setText("no,..!!");
    73. }
    74.  
    75. exFtp::~exFtp()
    76. {
    77.  
    78. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by marcel; 23rd February 2008 at 12:48. Reason: missing [code] tags

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: QFtp...doesnt seems to work ....!!!

    Well, I'm relatively new to Qt, but did you check the FTP example?
    Last edited by codeslicer; 23rd February 2008 at 14:03. Reason: broken link

  3. #3
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: QFtp...doesnt seems to work ....!!!

    yup...i have seen the example....nd taken all possible clues from it....but no use....still the prob. is there......

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp...doesnt seems to work ....!!!

    Either monitor the network traffic or the state of the QFtp object and see at which point the execution stops - see if the component connects to the host, logins, etc. At some point it probably fails to do its task but you don't notice it.

  5. #5
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp...doesnt seems to work ....!!!

    yup,u r rite,the execution is not proper ....but i think thr is problem in code,m nt sure if QFtp is used properly in the code....
    i cannt undestand what u mean by monitoring traffic..?...nd can u tell me a reliable site....which if provided downloads a file from it...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp...doesnt seems to work ....!!!

    Quote Originally Posted by salmanmanekia View Post
    yup,u r rite,the execution is not proper ....but i think thr is problem in code,m nt sure if QFtp is used properly in the code....
    Please use proper sentences instead of that awful sms slang.

    i cannt undestand what u mean by monitoring traffic..?
    I mean see what goes through your network interface card. There are many networking sniffer tools that do this - just search the net.

  7. #7
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp...doesnt seems to work ....!!!

    Thanks for the advice...
    I am not sure about network sniffer,is it realy necessary and dont you see any problem with the code....what i understand is that if code is fine then it should work and vice versa....aint it...!!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp...doesnt seems to work ....!!!

    Quote Originally Posted by salmanmanekia View Post
    I am not sure about network sniffer,is it realy necessary
    No, it's not necessary - you can go for the other approach I suggested. But the sniffer will show you what exactly happens during the connection (and if there is a connection at all). To monitor the state of the object you'll need to write some debugging code and deduce the problem from received output.

    dont you see any problem with the code...
    I don't see anything obvious.

    what i understand is that if code is fine then it should work and vice versa
    Then you understand incorrectly. The code might be fine but for example your personal firewall might be blocking the connection.

  9. #9
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp...doesnt seems to work ....!!!

    Worked the Program with Network sniffer,it doesnt detect any Incoming /Outgoing FTP packets,but the firewall i have installed asks me for the connection to be established when i run the program.....the firewall is of panda.....just for the sake of confirmation the address which i provide in FTP address bar is "ftp.trolltech.com"....is this right...??

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFtp...doesnt seems to work ....!!!

    Quote Originally Posted by salmanmanekia View Post
    Worked the Program with Network sniffer,it doesnt detect any Incoming /Outgoing FTP packets
    How about any packets going to ftp.trolltech.com? Can you connect to ftp.trolltech.com using your regular ftp client? Does the sniffer report the traffic on ftp ports then?

  11. #11
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFtp...doesnt seems to work ....!!!

    Can you connect to ftp.trolltech.com using your regular ftp client?
    Yup,the ftp address works fine.

Similar Threads

  1. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  2. QFtp Trouble !
    By Fastman in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 12:08
  3. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20
  4. why the qftp failed in qmainwindow?where is its signal?
    By cxl2253 in forum Qt Programming
    Replies: 15
    Last Post: 22nd April 2007, 13:51
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10

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.