Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Test Ftp server availability
Forum Updated to NodeBB v4.3 + New Features

How to Test Ftp server availability

Scheduled Pinned Locked Moved General and Desktop
19 Posts 3 Posters 6.7k Views 1 Watching
  • 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.
  • p3c0P Offline
    p3c0P Offline
    p3c0
    Moderators
    wrote on last edited by
    #7

    Hi,

    Did you check "authenticationRequired":http://qt-project.org/doc/qt-5/qnetworkaccessmanager.html#authenticationRequired ?
    Until valid credentials are given the signal is emitted again and again. If I understood you correctly this can be used in your case.

    157

    1 Reply Last reply
    0
    • B Offline
      B Offline
      beemaneni
      wrote on last edited by
      #8

      Hi sirop,
      The above examples does everything ..i get error from QNetworkReply as "NO ERROR". But i do not want to send that text file and verify the accessibility..
      Here we use
      @ reply = manager.put(QNetworkRequest(url), data);@
      i want to send only the ftp address as
      reply = manager.put or get (QNetworkRequest(url));

      I am not sure what function to use whether it is get or put or something else..?
      Let me give an example like i.e..the way we ping and find the accessibility of a network just with address

      Thanks
      Bala Beemaneni

      Bala B
      Infinite Computer systems
      Chennai

      1 Reply Last reply
      0
      • siropS Offline
        siropS Offline
        sirop
        wrote on last edited by
        #9

        I would then use:
        @QNetworkReply * QNetworkAccessManager::get(const QNetworkRequest & request)@

        To be, or not to be: that is the question:
        Whether ’tis nobler in the mind to suffer
        The slings and arrows of outrageous fortune,
        Or to take arms against a sea of troubles,
        And by opposing end them?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beemaneni
          wrote on last edited by
          #10

          Hi p3c0
          That signal emits only if authentication either username or password set mismatches.What i need is i want is on button click need to just login in to ftp server and on another button click logout from ftp server.

          Bala B
          Infinite Computer systems
          Chennai

          1 Reply Last reply
          0
          • B Offline
            B Offline
            beemaneni
            wrote on last edited by
            #11

            hi sirop,
            hi i did test that but of no use.Here is my code...
            @ QUrl testFtp("ftp://"+server);
            testFtp.setUserName(userId);
            testFtp.setPassword(password);
            testFtp.setPort(21);
            request.setUrl(testFtp);

            // reply = manager.put(request,testData);
            reply = manager.get(request);
            connect(reply,SIGNAL(readyRead()),this,SLOT(readData()));
            connect(reply,SIGNAL(uploadProgress(qint64,qint64)),this,SLOT(fileTransferProgress(qint64,qint64)));
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));
            connect(reply, SIGNAL(sslErrors(QList<QSslError>)),this, SLOT(slotSslErrors(QList<QSslError>)));@

            i get the error in Network Error says "202".
            i.e: QNetworkReply::ContentOperationNotPermittedError

            Bala B
            Infinite Computer systems
            Chennai

            1 Reply Last reply
            0
            • p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #12

              Well then another way would be to try to download file from ftp server. If it exists then on finished signal you should get NoError
              Eg:
              @
              manager->get(QNetworkRequest(QUrl("ftp://ftp.ed.ac.uk/pub/Unix/NT4_PlainPassword.reg")));
              ...

              void MainWindow::replyFinished(QNetworkReply *reply)
              {
              qDebug() << "Reply: " << reply->error(); //will show 0
              }
              @

              157

              1 Reply Last reply
              0
              • B Offline
                B Offline
                beemaneni
                wrote on last edited by
                #13

                hi dude...
                thats not the way i guess.We just have an ip address,user,password.Just we need to ensure whether we are reachable to the server or not..We do not know what are the contents in ftp.So we cant download a file.
                So cant we just login or connect to ftp server using QNAM?
                What about the QNetworkSession? I could not understand this..can u suggest something else

                Thanks for ur interest p3c0

                Bala B
                Infinite Computer systems
                Chennai

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #14

                  Deleted

                  157

                  1 Reply Last reply
                  0
                  • p3c0P Offline
                    p3c0P Offline
                    p3c0
                    Moderators
                    wrote on last edited by
                    #15

                    Another way would be to try to connect the server using QTcpSocket as
                    @
                    QTcpSocket *socket = new QTcpSocket;
                    connect(socket,SIGNAL(connected()),this,SLOT(onConnected()));
                    socket->connectToHost("192.168.1.145",21);
                    if(!socket->waitForConnected(2000)) {
                    qDebug() << "Not connected";
                    socket->abort();
                    }
                    @

                    If it succeeds then onConnected will be called immediately. But not sure if this is the recommended way.

                    157

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      beemaneni
                      wrote on last edited by
                      #16

                      hi ,
                      we may not have hostnames for all the ftp servers.So may not help much.
                      yeah using TCP will work.Bt right now i am googling for the QNAM API's which can do that.

                      Let me know if u get any from QNAM or supporting ones

                      Bala B
                      Infinite Computer systems
                      Chennai

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        beemaneni
                        wrote on last edited by
                        #17

                        Hii guys

                        Any updates on the previous ???
                        And i would like to add one more to this as..

                        1. When the network we try to connect is not in reach it does not give error on time..It takes a lot of time and some times it never returns any error..How do i handle this?

                           @    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),this, SLOT(slotError(QNetworkReply::NetworkError)));@
                          

                        i am catching above signal which takes a lot of time...
                        Are there any best methods?

                        Thanks

                        Bala B
                        Infinite Computer systems
                        Chennai

                        1 Reply Last reply
                        0
                        • siropS Offline
                          siropS Offline
                          sirop
                          wrote on last edited by
                          #18

                          Try to use QTimer ?

                          To be, or not to be: that is the question:
                          Whether ’tis nobler in the mind to suffer
                          The slings and arrows of outrageous fortune,
                          Or to take arms against a sea of troubles,
                          And by opposing end them?

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            beemaneni
                            wrote on last edited by
                            #19

                            Hi,
                            i feel there will be a straight way to do it with QNetworkAccessManager or with QNetworkReply.Probably we are missing that..

                            Thanks

                            Bala B
                            Infinite Computer systems
                            Chennai

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved