Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    QFtp: Problem connecting to host

    General and Desktop
    3
    15
    5771
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rizoritis last edited by

      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]

      1 Reply Last reply Reply Quote 0
      • hskoglund
        hskoglund last edited by

        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");

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          What about waitForConnected ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • R
            rizoritis last edited by

            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]

            1 Reply Last reply Reply Quote 0
            • hskoglund
              hskoglund last edited by

              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.

              1 Reply Last reply Reply Quote 0
              • R
                rizoritis last edited by

                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]

                1 Reply Last reply Reply Quote 0
                • hskoglund
                  hskoglund last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • R
                    rizoritis last edited by

                    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]

                    1 Reply Last reply Reply Quote 0
                    • hskoglund
                      hskoglund last edited by

                      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...

                      1 Reply Last reply Reply Quote 0
                      • R
                        rizoritis last edited by

                        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]

                        1 Reply Last reply Reply Quote 0
                        • hskoglund
                          hskoglund last edited by

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

                          1 Reply Last reply Reply Quote 0
                          • R
                            rizoritis last edited by

                            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]

                            1 Reply Last reply Reply Quote 0
                            • hskoglund
                              hskoglund last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post