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. QNetworkAccessManager: How to send data/file from ftp connection
Qt 6.11 is out! See what's new in the release blog

QNetworkAccessManager: How to send data/file from ftp connection

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 2.1k 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.
  • M Offline
    M Offline
    MimCimm
    wrote on last edited by
    #1

    I try to send data/file to current directory( folder that I want) from windows to Linux ?
    For this Firsltyi I tried to download some file from Linux.
    Here is my code:

    QUrl url("ftp://192.168.100.70/root/coming.txt");
      url.setUserName("admin");
      url.setPassword("admin");
      url.setPort(21);
      QNetworkRequest request(url);
      manager=new QNetworkAccessManager(this);
      reply = manager->get(request);
      connect(reply, SIGNAL(readyRead()), SLOT(downloadReadyRead()));
      connect(reply, SIGNAL(finished()), SLOT(downloadFinished()));
      qDebug()<<reply->readAll();
    

    and secondly I tried Qt's example download manager and tried:

    QNetworkRequest request(url);
      QByteArray applicationUserName = "admin";
      QByteArray applicationUserPassword = "admin";
      request.setRawHeader("Username",applicationUserName);
      request.setRawHeader("Password",applicationUserPassword);
      currentDownload = manager.get(request);
      connect(currentDownload, SIGNAL(downloadProgress(qint64,qint64)),
              SLOT(downloadProgress(qint64,qint64)));
      connect(currentDownload, SIGNAL(finished()),
              SLOT(downloadFinished()));
      connect(currentDownload, SIGNAL(readyRead()),
              SLOT(downloadReadyRead()));
    

    But it returns me:
    Failed: Logging in to 192.168.100.70 failed: authentication required

    But when I try to connect from fileZilla with this authentication everything is ok.
    Do you have any suggestion to me.
    What I really want to do is: I want to upload my files into directories that I want from Windows to Linux by ftp connection (exactly like fileZille, almost same but I want to choose ip and path in my code as a hardcode )

    I will be plesuare for any help and suggestion.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by
      #2

      Did you also set the username and password to the url in the second method?

      M 1 Reply Last reply
      0
      • B Bonnie

        Did you also set the username and password to the url in the second method?

        M Offline
        M Offline
        MimCimm
        wrote on last edited by
        #3

        @Bonnie No I just did that;
        request.setRawHeader("Username",applicationUserName);
        request.setRawHeader("Password",applicationUserPassword);

        B 1 Reply Last reply
        0
        • M MimCimm

          @Bonnie No I just did that;
          request.setRawHeader("Username",applicationUserName);
          request.setRawHeader("Password",applicationUserPassword);

          B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

          @MimCimm
          FTP should accept username and password in the url.
          But your first code snippet seems not having right design.
          So I think you should use the qt example, but set the username and password in the url as in the first method.

          M 1 Reply Last reply
          0
          • B Bonnie

            @MimCimm
            FTP should accept username and password in the url.
            But your first code snippet seems not having right design.
            So I think you should use the qt example, but set the username and password in the url as in the first method.

            M Offline
            M Offline
            MimCimm
            wrote on last edited by
            #5

            @Bonnie Unfortunatelly, İt also return

            Failed: Logging in to 192.168.100.70 failed: authentication required
            
            JonBJ 1 Reply Last reply
            0
            • M MimCimm

              @Bonnie Unfortunatelly, İt also return

              Failed: Logging in to 192.168.100.70 failed: authentication required
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @MimCimm
              Verify the connection stuff saved/specified in your working FileZilla connector. For example, it might be using a different port. Anyway, check that out to make certain your code is trying to do the same.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bonnie
                wrote on last edited by
                #7

                I just setup a local ftp server and tested with the downloadmanager example, setting username and password to the url totally works.
                I got

                Downloading ftp://admin:admin@127.0.0.1/root/coming.txt...
                [###    ]      0.0 bytes/sec
                Succeeded.
                1/1 files downloaded successfully
                
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MimCimm
                  wrote on last edited by
                  #8
                  This post is deleted!
                  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