Results 1 to 3 of 3

Thread: QFtp Trouble !

  1. #1
    Join Date
    Jul 2007
    Location
    BY.Minsk
    Posts
    90
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QFtp Trouble !

    QT 4.3 +VS2005:

    Qt Code:
    1. class CFtp: public QFtp
    2. {
    3. Q_OBJECT
    4. public:
    5. CFtp(QObject *parent = 0);
    6. ~CFtp();
    7. qint16 ConnectToFTP(QString cFtpServer, QString cLogin, QString cPass);
    8. void CloseFtp();
    9. private:
    10. QFtp *m_pFtp;
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CFtp::CloseFtp()
    2. {
    3. m_pFtp->close();
    4.  
    5. //if(m_pFtp != NULL)
    6. //delete(m_pFtp);
    7. }
    8.  
    9. qint16 CFtp::ConnectToFTP(QString cFtpServer, QString cLogin, QString cPass)
    10. {
    11. m_pFtp = new QFtp;
    12.  
    13. qint16 nStateConnect= -1;
    14. qint16 nLoginConnect = -1;
    15.  
    16. nStateConnect = m_pFtp->connectToHost(cFtpServer);
    17. nLoginConnect = m_pFtp->login(cLogin,cPass);
    18.  
    19. //QApplication::beep();
    20.  
    21. return 1;
    22. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Connection::processReadyRead()
    2. {
    3. ...
    4. ...
    5. ...
    6. case 4: //DELETE FILE(4)
    7. {
    8.  
    9. CFtp ftp;
    10. ftp.ConnectToFTP("127.0.0.1","pas","amal");
    11. ftp.CloseFtp();
    12. }
    13. break;
    14. ...
    15. ...
    16. ...
    17. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void FortuneThread::run()
    2. {
    3. Connection connection;
    4. if(!connection.setSocketDescriptor(socketDescriptor))
    5. {
    6. emit error(connection.error());
    7. return;
    8. }
    9. //connect(&connection, SIGNAL(SendMSG(QString)), this, SIGNAL(SendMSG(QString)));
    10. connect(&connection, SIGNAL(disconnected()), this, SLOT(deleteConnection()));
    11. exec();
    12. }
    To copy to clipboard, switch view to plain text mode 


    But connection or occurs and hangs:

    07/08/07 11:04:51, 499, 127.0.0.1, , new connection from 127.0.0.1 on 127.0.0.1:21
    07/08/07 11:04:51, 499, 127.0.0.1, , hostname resolved : localhost
    07/08/07 11:04:51, 499, 127.0.0.1, , sending welcome message.
    07/08/07 11:04:51, 499, 127.0.0.1, , 220 Gene6 FTP Server v3.9.0 (Build 2) ready...

    or it is not connected in general.
    Connections are closed only after timeout or after closing the appendix.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QFtp Trouble !

    Have you taken look at the FTP example? Above snippet is a bit confusing. CFtp already is a QFtp so there is no need to wrap yet another QFtp as a member variable. Also, be aware that QFtp::connectToHost() does not block but returns immediately. Changes in connection state are informed later via signals.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFtp Trouble !

    Well, I already told you to move the connect statement from the Connection constructor.
    Can you post the whole code now, because the parts you posted don't really show anything.

    So, it is most likely a thread/synchronization problem.

    Regards

Similar Threads

  1. QFtp sample program
    By comlink21 in forum Qt Programming
    Replies: 7
    Last Post: 27th April 2012, 09:59
  2. how to use qftp to upload file in just one procedure?
    By cxl2253 in forum Qt Programming
    Replies: 4
    Last Post: 23rd April 2007, 10:57
  3. why the qftp failed in qmainwindow?where is its signal?
    By cxl2253 in forum Qt Programming
    Replies: 15
    Last Post: 22nd April 2007, 14:51
  4. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 19:10
  5. Replies: 18
    Last Post: 6th February 2007, 15:06

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.