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. Qt FTP Solution

Qt FTP Solution

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 7.1k Views
  • 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.
  • K Offline
    K Offline
    Kats
    wrote on 2 Mar 2017, 21:18 last edited by
    #1

    Hey!

    I'm a new user to the Qt platform and only vaguely understand the power it provides, but I'm using it for a project in-house that I really just need a simple solution/tutorial/walkthrough of how to accomplish.

    As I understand and have read other articles, Qt 5 removed built-in FTP functionality. Another post mentioned something about QNetwork handling this, but I'm entirely unclear how this is supposed to work? What classes do I use? How do I implement those classes? What are the functions I should be looking up? Are there any decently commented tutorials that show me how a normal Qt user would set this up? (The code examples on the site are not well documented at all. Just throwing raw, nearly-uncommented code at you and expecting you to just intrinsically understand what's going on.)

    As I said before, I've never used the Qt library before, but I can't imagine that it's really so complicated that I can't just include QNetwork and create a class to handle everything with a few lines of code.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 2 Mar 2017, 21:22 last edited by
      #2

      Hi, welcome to the forum. The simple solution is to use https://github.com/qt/qtftp.

      1 Reply Last reply
      1
      • T Offline
        T Offline
        TioRoy
        wrote on 2 Mar 2017, 21:25 last edited by
        #3

        You can check the docs too:

        http://doc.qt.io/qt-5/qtnetwork-programming.html

        Or search some examples like this:

        QString filename="Data.txt";
        QFile file( filename );
        file.open(QIODevice::ReadWrite);
        file.write("HELLO") ;
        
        QUrl urlup("ftp://127.0.0.1/file.txt");
        urlup.setPassword("123");
        urlup.setUserName("user");
        urlup.setPort(21);
        QNetworkAccessManager *nam = new QNetworkAccessManager;
        QNetworkRequest requp(urlup);
        nam->put(requp,&file);
        file.close();
        
        K 1 Reply Last reply 2 Mar 2017, 21:30
        4
        • T TioRoy
          2 Mar 2017, 21:25

          You can check the docs too:

          http://doc.qt.io/qt-5/qtnetwork-programming.html

          Or search some examples like this:

          QString filename="Data.txt";
          QFile file( filename );
          file.open(QIODevice::ReadWrite);
          file.write("HELLO") ;
          
          QUrl urlup("ftp://127.0.0.1/file.txt");
          urlup.setPassword("123");
          urlup.setUserName("user");
          urlup.setPort(21);
          QNetworkAccessManager *nam = new QNetworkAccessManager;
          QNetworkRequest requp(urlup);
          nam->put(requp,&file);
          file.close();
          
          K Offline
          K Offline
          Kats
          wrote on 2 Mar 2017, 21:30 last edited by
          #4

          @TioRoy Wow. That is probably the simplest and cleanest looking example that I've seen for something like this in a long time. Thank you so much. I hate for it to seem like I'm just asking other people to do the work for me, but I really have no clue how this library works and it's absolutely massive. If I weren't working on an actual project for my workplace, I'd be more inclined to really sit down and learn it more, but I more or less just really need something working with the time crunch I've been on lately.

          I'll try it out and let you know if I have any more questions.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kats
            wrote on 6 Mar 2017, 19:28 last edited by
            #5

            I'm actually running into a really weird issue. QNetworkAccessManager has no ability to use a mkdir command of any kind on the FTP server according this this post?

            I have to hunt for, download, figure out how to install and link to a third-party addon library for QFtp compatibility in Qt5 to utilize a function that was readily available in the previous version? Did the Qt developers really make the worst mistake of any library and blatantly remove functionality from future versions with no replacement or is this post just misleading and there actually is a mkdir or similar command available to QNetworkAccessManager or any other Qt5 standard class?

            V 1 Reply Last reply 7 Mar 2017, 08:13
            0
            • K Kats
              6 Mar 2017, 19:28

              I'm actually running into a really weird issue. QNetworkAccessManager has no ability to use a mkdir command of any kind on the FTP server according this this post?

              I have to hunt for, download, figure out how to install and link to a third-party addon library for QFtp compatibility in Qt5 to utilize a function that was readily available in the previous version? Did the Qt developers really make the worst mistake of any library and blatantly remove functionality from future versions with no replacement or is this post just misleading and there actually is a mkdir or similar command available to QNetworkAccessManager or any other Qt5 standard class?

              V Offline
              V Offline
              VRonin
              wrote on 7 Mar 2017, 08:13 last edited by VRonin 3 Jul 2017, 08:15
              #6

              @Kats said in Qt FTP Solution:

              Did the Qt developers really [...] remove functionality from future versions with no replacement

              Yes and this is not the only instance. The point is that a migration in technology forced the change. I also do not advise to go back to QtFtp module as it's unsupported.

              In reality, while we got used (and is convenient) to have everything we need packed from Qt, it's quite natural to have libraries that specifically focus on one task rather than a catch all as the Qt framework is.

              For networking* my advice is to set Qt aside and use a well established, actively maintained library that focus on the task you want to achieve. My suggestion here is libcurl as its popularity is unmatched in my opinion

              P.S.
              The example posted above is leaking memory like a bandit


              *over FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMTP, SMTPS, Telnet and TFTP

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 7 Mar 2017, 12:23 last edited by mrjj 3 Jul 2017, 12:48
                #7

                Hi
                If you go libcurl route, maybe this will help
                https://github.com/grynko/curlite

                Please see next post.

                V 1 Reply Last reply 7 Mar 2017, 12:40
                1
                • M mrjj
                  7 Mar 2017, 12:23

                  Hi
                  If you go libcurl route, maybe this will help
                  https://github.com/grynko/curlite

                  Please see next post.

                  V Offline
                  V Offline
                  VRonin
                  wrote on 7 Mar 2017, 12:40 last edited by
                  #8

                  @mrjj https://github.com/jpbarrette/curlpp is more mature but I still didn't manage to get a reliable and robust build on Windows (MSVC2013), great on other platforms though

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  1
                  • K Offline
                    K Offline
                    Kats
                    wrote on 7 Mar 2017, 14:13 last edited by Kats 3 Jul 2017, 14:15
                    #9

                    Well, I managed to get the QFtp working regardless. I have no ambition not to use it simply due to the time constraints on my project. I'm 100% sure there are better, more robust solutions out there, but I simply don't have the time to hunt and search through all of them. I'm already using the Qt Library, it's just easier to keep with the theme since QFtp objects are so easy to work with and they have the level of control that I need.

                    Before Qt, I'd messed with FtpLib, Lib Ftp and LibCurl and couldn't get any of them to compile properly. It became 2 or 3 days of an absolute nightmare with zero results, so I just went with a trusted option that actually works: Qt.

                    Side Note: Thank you guys so much. This community is so much more pleasant to work with than StackOverflow. You're actually informative!

                    V 1 Reply Last reply 7 Mar 2017, 14:59
                    1
                    • K Kats
                      7 Mar 2017, 14:13

                      Well, I managed to get the QFtp working regardless. I have no ambition not to use it simply due to the time constraints on my project. I'm 100% sure there are better, more robust solutions out there, but I simply don't have the time to hunt and search through all of them. I'm already using the Qt Library, it's just easier to keep with the theme since QFtp objects are so easy to work with and they have the level of control that I need.

                      Before Qt, I'd messed with FtpLib, Lib Ftp and LibCurl and couldn't get any of them to compile properly. It became 2 or 3 days of an absolute nightmare with zero results, so I just went with a trusted option that actually works: Qt.

                      Side Note: Thank you guys so much. This community is so much more pleasant to work with than StackOverflow. You're actually informative!

                      V Offline
                      V Offline
                      VRonin
                      wrote on 7 Mar 2017, 14:59 last edited by VRonin 3 Jul 2017, 16:29
                      #10

                      @Kats said in Qt FTP Solution:

                      Before Qt, I'd messed with [..] LibCurl and couldn't get any of them to compile properly

                      example commands to build and install libcurl on Windows MSVC 2013 32bit
                      assuming you have openssl in C:\openssl and zlib in C:\zlibBuild this will place the result in C:\libcurl

                      pushd C:\
                      CALL "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/vcvarsall.bat"
                      popd
                      echo on
                      mkdir deps
                      xcopy C:\openssl\* deps\ /S /Y
                      xcopy C:\zlibBuild\* deps\ /S /Y
                      cd winbuild
                      nmake /f Makefile.vc mode=dll WITH_DEVEL=../deps WITH_SSL=dll WITH_ZLIB=dll VC=12 DEBUG=yes 
                      nmake /f Makefile.vc mode=dll WITH_DEVEL=../deps WITH_SSL=dll WITH_ZLIB=dll VC=12 DEBUG=no
                      cd ..\
                      if not exist "C:\libcurl" mkdir "C:\libcurl"
                      if not exist "C:\libcurl\include" mkdir "C:\libcurl\include"
                      xcopy include\* C:\libcurl\include /S /Y
                      xcopy builds\libcurl-vc12-x86-debug-dll-ssl-dll-zlib-dll-ipv6-sspi\* C:\libcurl\ /S /Y
                      xcopy builds\libcurl-vc12-x86-release-dll-ssl-dll-zlib-dll-ipv6-sspi\* C:\libcurl\ /S /Y
                      

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      3
                      • K Offline
                        K Offline
                        Kats
                        wrote on 8 Mar 2017, 22:22 last edited by
                        #11

                        Okay, I'm running into an extremely large problem, now.

                        I had QFtp working where it would connect to the server perfectly fine, but when I come back into the office today and pull up the build, it DOES NOT CONNECT. When I use it, it doesn't even pretend like it's trying to connect.

                        I've been using a threaded loop to monitor QFtp's state and it always stays at 3. I have a slot setup to catch any changes, but it never does. The Ftp server also never sees the attempted connection either.

                        I have no idea what's going on because apparently this is a problem that nobody in the history of Qt has ever had before.

                        M 1 Reply Last reply 8 Mar 2017, 22:24
                        0
                        • K Kats
                          8 Mar 2017, 22:22

                          Okay, I'm running into an extremely large problem, now.

                          I had QFtp working where it would connect to the server perfectly fine, but when I come back into the office today and pull up the build, it DOES NOT CONNECT. When I use it, it doesn't even pretend like it's trying to connect.

                          I've been using a threaded loop to monitor QFtp's state and it always stays at 3. I have a slot setup to catch any changes, but it never does. The Ftp server also never sees the attempted connection either.

                          I have no idea what's going on because apparently this is a problem that nobody in the history of Qt has ever had before.

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 8 Mar 2017, 22:24 last edited by
                          #12

                          @Kats
                          Hi
                          If you restart whole pc, will it then connect again?
                          Also make sure firewall or scanner is not blocking it.

                          1 Reply Last reply
                          2
                          • K Offline
                            K Offline
                            Kats
                            wrote on 8 Mar 2017, 22:29 last edited by
                            #13

                            I can connect to the server through every other FTP service on my computer (all browsers and FileZilla connect instantly).

                            QFtp is the only service that does not connect. It's exhibiting the exact same behavior as if I'm attempting to connect to the wrong address, but this is simply not possible because the address I'm connecting to (192.168.1.26) is available to all local devices. I'm using the exact same address and credentials as on everything else but is acting like the ftp server doesn't exist.

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              VRonin
                              wrote on 10 Mar 2017, 13:20 last edited by
                              #14

                              My money is on firewall blocking it

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              1 Reply Last reply
                              1
                              • K Offline
                                K Offline
                                Kats
                                wrote on 10 Mar 2017, 22:06 last edited by Kats 3 Oct 2017, 22:10
                                #15

                                It was not a firewall. It's because QFtp objects apparently can't be instantiated from inside of a thread. They can only be created inside the main thread of the program, regardless of their scope. Fixing that solved my issue and I've since completed what I was working on.

                                1 Reply Last reply
                                1
                                • K Offline
                                  K Offline
                                  Kats
                                  wrote on 13 Mar 2017, 13:23 last edited by
                                  #16

                                  Hey, again, I can't thank you guys enough for you input on helping me troubleshoot this project, but it's helped both show me a newfound appreciation (and possibly future dependency) for Qt as well as streamline my current production environment, which is really helpful!

                                  So thanks so much, even if my frustration peaked through every now and again.

                                  1 Reply Last reply
                                  1

                                  3/16

                                  2 Mar 2017, 21:25

                                  13 unread
                                  • Login

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