QFtp: Problem connecting to host



  • Hello,

    I am using Qt5 and have installed the deprecated qFtp module. I was able to get the example code (FtpWindow) running and connecting to an ftp server using a URL. For my application, I am trying to use my desktop Qt application to connect through Ethernet to a local WEC7 computer. I thought I would be able to change the two connect lines in the FtpWindow::connectToFtp() function as follows:

    @ ftp->connectToHost("192.168.0.232");
    ftp->login("anonymous", "ftp");@

    The IP here is the IP of the WEC7 PC. However, when I run the application, the UI just notifies me that it is trying to connect forever even though I have seen it get past these two commands using debug messages. I have no problem transferring files over FTP using the command line on my PC and connecting to the server on the WEC7 machine.

    The problem seems to be something with using IP addresses and connecting locally. Also, the username and password might have something to do with it. I a complete noob when it comes to FTP and Qt so any insight that anyone can provide would be helpful. Maybe even a small example of using Qt to do a file transfer over Ethernet would be good.

    Thanks!



  • Just guessing, but
    ftp->connectToHost("192.168.0.232);
    should be ftp->connectToHost("192.168.0.232");



  • I had that. I mistyped it here. That isn't the problem.

    [quote author="hskoglund" date="1398451159"]Just guessing, but
    ftp->connectToHost("192.168.0.232);
    should be ftp->connectToHost("192.168.0.232");[/quote]



  • Sorry! Anyway: another guess, since you can connect ok but not locally, maybe it's because the traffic is too fast on your LAN, i.e. try to slow down the connection for example by inserting ProcessEvents:

    QCoreApplication::ProcessEvents();
    ftp->connectToHost(“192.168.0.232");
    QCoreApplication::ProcessEvents();
    ftp->login("anonymous", "ftp");


  • Lifetime Qt Champion

    Hi,

    What about waitForConnected ?



  • For some reason it is working now without doing anything. I have another problem though. It seems that there are no files or directories showing from the connected server. The Qt side says it is connected (how would I verify that it is actually connected?) and that the directory is empty. I know that it is not empty. I am not sure if it is not actually connected or if there is something extra needed to see what is in the directory?

    EDIT:
    Just for reference, I am using the below code to connect and it actually says I am connected and logged in. Not sure why the files and directories don't show...

    @void FtpWindow::connectToFtp()
    {
    //![1]
    ftp = new QFtp(this);
    connect(ftp, SIGNAL(commandFinished(int,bool)),
    this, SLOT(ftpCommandFinished(int,bool)));
    connect(ftp, SIGNAL(listInfo(QUrlInfo)),
    this, SLOT(addToList(QUrlInfo)));
    connect(ftp, SIGNAL(dataTransferProgress(qint64,qint64)),
    this, SLOT(updateDataTransferProgress(qint64,qint64)));

    fileList->clear();
    currentPath.clear();
    isDirectory.clear();
    

    //![1]

    //![2]
    QUrl url(ftpServerLineEdit->text());
    if (!url.isValid() || url.scheme().toLower() != QLatin1String("ftp")) {
    ftp->connectToHost(ftpServerLineEdit->text(), 21);
    //ftp->login("anonymous", "ftp");
    ftp->login();
    QCoreApplication::processEvents(0, 100);
    qDebug() << ftp->state();
    } else {
    ftp->connectToHost(url.host(), url.port(21));

        if (!url.userName().isEmpty())
            ftp->login(QUrl::fromPercentEncoding(url.userName().toLatin1()), url.password());
        else
            ftp->login();
        if (!url.path().isEmpty())
            ftp->cd(url.path());
    }
    

    //![2]

    if ( ftp->Connected )
    {
        if ( ftp->LoggedIn )
        {
        fileList->setEnabled(true);
        connectButton->setEnabled(false);
        connectButton->setText(tr("Disconnect"));
        statusLabel->setText(tr("Connecting to FTP server %1...")
                             .arg(ftpServerLineEdit->text()));
        }
        else
        {
            connectButton->setEnabled(false);
            connectButton->setText(tr("Disconnect"));
            statusLabel->setText(tr("Not logged into FTP server %1...")
                                 .arg(ftpServerLineEdit->text()));
        }
    }
    else
    {
        statusLabel->setText(tr("Could not connect to FTP server %1...")
                             .arg(ftpServerLineEdit->text()));
    }
    

    }@

    [quote author="hskoglund" date="1398452374"]Sorry! Anyway: another guess, since you can connect ok but not locally, maybe it's because the traffic is too fast on your LAN, i.e. try to slow down the connection for example by inserting ProcessEvents:

    QCoreApplication::ProcessEvents();
    ftp->connectToHost(“192.168.0.232");
    QCoreApplication::ProcessEvents();
    ftp->login("anonymous", "ftp");
    [/quote]



  • Hi. if you try the same connection from Internet Explorer, e.g. type "ftp://192.168.0.232" and that shows files/directories, then you cold check that the qFTP connection is real by opening a CMD window and type netstat, it should list 192.168.0.232:ftp .. ESTABLISHED.
    If it's established and you don't see any files, try slowing down the traffic by doing those QCoreApplication::ProcessEvents()...

    EDIT: Oh, better is to try SGaist's suggestion waitForConnected() it's a good idea, because connectToHost() does not block.



  • I did as you suggested. I see the files in IE, however when I type netstat in the cmd window I do not see that IP as established...

    [quote author="hskoglund" date="1398865570"]Hi. if you try the same connection from Internet Explorer, e.g. type "ftp://192.168.0.232" and that shows files/directories, then you cold check that the qFTP connection is real by opening a CMD window and type netstat, it should list 192.168.0.232:ftp .. ESTABLISHED.
    If it's established and you don't see any files, try slowing down the traffic by doing those QCoreApplication::ProcessEvents()...

    EDIT: Oh, better is to try SGaist's suggestion waitForConnected() it's a good idea, because connectToHost() does not block.[/quote]



  • Ok try with ftp->waitForConnected() between connectToHost() and login()



  • There is no such thing as waitForConnected().

    EDIT: I was actually able to connect using the Qt program and when viewing the result of netstat I see that the connection was established. The only problem now is that I do not see any files.

    [quote author="hskoglund" date="1398866292"]Ok try with ftp->waitForConnected() between connectToHost() and login()[/quote]



  • Sorry, nice try :-(

    But there should be other ways to slow it down, for example, do the connectoToHost() in one function and login() in another...



  • I am connected as shown by the netstat check that you suggested. The problem is I do not see files. Are you saying I need time for files to show or is that for connecting. If it is for connecting I already solved that issue. My new issue is just that it thinks the directory is empty.

    [quote author="hskoglund" date="1398866758"]Sorry, nice try :-(

    But there should be other ways to slow it down, for example, do the connectoToHost() in one function and login() in another...
    [/quote]



  • Hi, I think it needs more time for the files to show (because connectToHost() returns directly, so that login() perhaps is called too early).



  • Do you also think it could be a matte of the remote server being an active or passive ftp connection? Maybe I have to manually get() the files individually??

    [quote author="hskoglund" date="1398869401"]Hi, I think it needs more time for the files to show (because connectToHost() returns directly, so that login() perhaps is called too early).
    [/quote]



  • Hi, regardless I think it's a good idea to try with a ftp get() anyway, if that succeeds it gives you more diagnostic.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.