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 can i download file from servrer right?
Forum Updated to NodeBB v4.3 + New Features

How can i download file from servrer right?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 6 Posters 8.0k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on last edited by
    #1

    Hellow, i need to download file from server
    http://rizek.ucoz.ru/RizekQssEditor/a.txt
    I write:
    @ QFile file("a.txt");
    QFtp ftp;
    if (file.open(QIODevice::WriteOnly)){
    ftp.connectToHost("rizek.ucoz.ru");
    ftp.cd("RizekQssEditor");
    ftp.get("a.txt", &file);
    }@
    But when i download it, file in dir is empty, why is it?
    Advance many thanks for your help!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      First of all that's a HTTP URL, not a FTP one. Why do you want to download it with FTP?
      Second: since it's a simple "get", you can use QNAM and not QFtp.
      Third: can you make a complete testcase? Are you waiting for the transfer to finish?

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        You should check the return values of get(...) for instance.
        Furthermore, you should consult the documentation of "QFtp::get":http://doc.qt.nokia.com/4.7/qftp.html#get it sais :
        "The function does not block and returns immediately. The command is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by commandStarted() and commandFinished()."
        So, you might exit the routine your snippet is from before the ftp is executed.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on last edited by
          #4

          I try to use QHttp:
          @ QFile * file = new QFile("rizek.ucoz.ru");
          QHttp * http = new QHttp;
          if (file->open(QIODevice::WriteOnly)){
          http->setHost("foto.rambler.ru");
          http->get("/RizekQssEditor/a.txt", file);
          connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(replyFinished(int,bool)));@
          \Slot replyFinished
          @void Updater::replyFinished(int id,bool error)
          {
          label->setText(QVariant(id).toString() + " " + QVariant(error).toString());
          }@
          And text of label is "2 false" and there are empty file in the dir of program
          I am copied this example from the textbook, why it doesn not work?

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            You seem to have a hang of ignoring return values. May be you should check those as well. AFAIK the ids are incremented each time with a request at least for QFtp. So, presumably you are tracking the correct request, but you should make sure.
            Did you make sure that the file on your server has some contents?

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              QHttp is obsolete, use QNetworkAccessManager instead. The procedure is almost the same.

              bq. This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Ruzik
                wrote on last edited by
                #7

                bq. Did you make sure that the file on your server has some contents?

                Yes, i am sure

                @May be you should check those as well.@

                How can i do it?

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  koahnig
                  wrote on last edited by
                  #8

                  setHost and get return both an integer value. So you could assign the return values to int and check them. Like

                  @ QFile * file = new QFile("rizek.ucoz.ru");
                  QHttp * http = new QHttp;
                  if (file->open(QIODevice::WriteOnly)){
                  int ret0 = http->setHost("foto.rambler.ru");
                  int ret1 = http->get("/RizekQssEditor/a.txt", file);
                  connect(http, SIGNAL(requestFinished(int,bool)), this, SLOT(replyFinished(int,bool)));@

                  You could use qDebug() for output or even write them to a file. But that is standard, so there should not be need to explain.

                  However, did you notice
                  [quote author="Lukas Geyer" date="1309465555"]QHttp is obsolete, use QNetworkAccessManager instead. The procedure is almost the same.

                  bq. This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.[/quote]

                  He is correct to switch to QNetworkAccessManager then.

                  There seem to be already an example for what you are trying to do:
                  "http example":http://doc.qt.nokia.com/4.7/network-http.html

                  That is probably a good start for you. I did not try out, but typically the Qt are working and you can start to do your modifications from there.

                  Vote the answer(s) that helped you to solve your issue(s)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Ruzik
                    wrote on last edited by
                    #9

                    You was right, i must be use QNetworkAccessManagder, i think that classes QHttp and QFtp dont work anymore

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kkrzewniak
                      wrote on last edited by
                      #10

                      QHttp is there to keep backward compatibility(it does work) and should not be used for new software.

                      Try using assistant more, it usually takes less time than waiting for an answer on devnet ;). And Qt has such grate documentation. BTW I think that the "This class is obsolete." part of QHttp documentation should be in red or any other eye catching color, because it's not uncommon to see people still trying to use it.

                      Me, Grimlock, not "nice dino". ME BASH BRAINS!

                      1 Reply Last reply
                      0
                      • K Offline
                        K Offline
                        koahnig
                        wrote on last edited by
                        #11

                        @kkrzewniak You are certainly right with your comment on QHttp and the same is true for QFtp.

                        I like your idea of color coding when classes are no longer first choice. Even those who are careful manual readers ( I guess those are rare in development ;-) ) do not catch the deprecation of classes. Most of the time you are just looking which method you need. And that's it.

                        Vote the answer(s) that helped you to solve your issue(s)

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jim_kaiser
                          wrote on last edited by
                          #12

                          If you want to know what you were doing wrong with QHttp.. I had posted an example recently.. take a look at "this thread":http://developer.qt.nokia.com/forums/viewthread/6759

                          Your slot is called multiple times but you should only react when the httpRequestId is matched.

                          [ Edit: NOTE: QHttp is obsolete as pointed out by many others and shouldn't be used. ]

                          1 Reply Last reply
                          0
                          • K Offline
                            K Offline
                            kkrzewniak
                            wrote on last edited by
                            #13

                            @jim_kaiser why are you telling people to use deprecated classes? You should stop such practices at once!! You are spreading confusion!!
                            Fixed: thanks jim_kaiser

                            Me, Grimlock, not "nice dino". ME BASH BRAINS!

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              jim_kaiser
                              wrote on last edited by
                              #14

                              I simply pointed out what was wrong with his code. At the time I used the QHttp (the code posted).. there was no other option. I think it is pretty clear to everybody and spelled out many times that it is deprecated now. Honestly, I found that out myself just recently over here.

                              Anyways, I apologize for the confusion and yes.. the OP in the thread I linked would also be better off using the QNetworkManager classes currently. Thanks for adding that info to the thread.

                              [ Edit: Have edited my "post":http://developer.qt.nokia.com/forums/viewreply/39453/ and added the code using the QNetworkManager. Once again sorry about that.. honest mistake..]

                              [ Edit2: @kkrzewniak: Off-topic but its "deprecated" not "depreciated".. we all get it.. but just saying.. :-) ]

                              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