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

Issue with FTP using QNetworkAccessManager



  • Hi evereyone,

    I want to use QNetworkAccessManager in order to download a file from a FTP server. Basicly, I use the following code according to the documentation:

    myNetworkManager = new QNetworkAccessManager(this);
    QUrl url("ftp://FTP_server:1234@192.168.1.62:2121/file_1.png");
    myNetworkRequest.setUrl(url);
    myNetworkReply = myNetworkManager->get(myNetworkRequest);
    

    It gives me this error:

    qt.network.ssl: No functional TLS backend was found
    qt.network.ssl: No functional TLS backend was found
    qt.network.ssl: No functional TLS backend was found
    qt.network.ssl: No TLS backend is available
    

    After some research, it appears the openSSL library is not include in QT. I found a bunch of tutorial explaining how to install it, but it not seems so easy.

    So is this the only solution, or do I do something wrong using QNetworkAccessManager for my FTP request ?

    Thanks all.


  • Lifetime Qt Champion

    Yes, it's one way to implement it.


  • Moderators

    @CLBSII
    what type of FTP server is this?
    normally FTP is unencrypted. But FTP over SSL first connects via FTP and then switches to a secure encrypted port.

    Installation of OpenSSL libs is actually pretty easy.
    Simply copy the 2 OpenSSL libs either next to your executable or ensure that they are in the PATH env variable (assuming you are on Windows)
    https://wiki.openssl.org/index.php/Binaries
    or install it via the Qt MaintenanceTool

    What Qt version btw?



  • @raven-worx
    To be honest, my FTP server is running on a distant computer using this Python Library, so I'm not sure for the type.

    Well it seems you was right, I successfully installed the OpenSSL lib following your link and the error disappeared. Thanks for helping (and yes I'm on Windows).

    However, my code doesn't seems to work. I mean, there are no errors, bu the file is not downloaded and the FTP server doesn't receive any notifications.

    I spent my all day searching for a good example, but all I could get was this code. I also know I need to do something like this after:

        m_file.setFileName("file_1.png");
        m_file.open(QIODevice::WriteOnly | QIODevice::Append);
        m_file.write(myNetworkReply->readAll());
    

    But it doesn't change anything. No files created. Seems like the myNetworkReply var is empty.


  • Moderators

    @CLBSII
    when exactly do you execute this code?



  • @raven-worx
    During the initialization of my application. I call function that doing all those things:

    void MyApp::DownloadFtp()
    {
       myNetworkManager = new QNetworkAccessManager(this);
       QUrl url("ftp://Vprint_FTP:1234@192.168.1.62:2121/file_1.png");
       qDebug()<<url;
       myNetworkRequest.setUrl(url);
       myNetworkReply = myNetworkManager->get(myNetworkRequest);
    
       m_file.setFileName("file_1.png");
       m_file.open(QIODevice::WriteOnly | QIODevice::Append);
       m_file.write(myNetworkReply->readAll());
    }
    

    I don't know if it answer to your question ?
    One thing that bother me is that the qDebug line returns me :

    QUrl("sftp://Vprint_FTP@192.168.1.62:2121/1.png")
    

    It is the same line that I set, without the password. Is it normal ?


  • Moderators

    @CLBSII
    this way the request probably wasnt event sent yet.
    you must connect to the finished signal of the reply and then read the data (and error checking of course)



  • @raven-worx
    I'm not sure to understand. Do you mean I have to add some temporisation at some point ?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    No, QNAM is an asynchronous class, you need to use signal and slots to implement your data processing once the answer fully arrived.



  • Thanks for your time.

    I found this example. Is it relevant with what you explained to me ?


  • Lifetime Qt Champion

    Yes, it's one way to implement it.


Log in to reply