Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QNetworkAccessManager: How to send data/file from ftp connection



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



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



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



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



  • @Bonnie Unfortunatelly, İt also return

    Failed: Logging in to 192.168.100.70 failed: authentication required
    


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



  • 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
    


  • This post is deleted!

Log in to reply