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 6.4.2 and FTP Upload - Windows 11
Forum Updated to NodeBB v4.3 + New Features

Qt 6.4.2 and FTP Upload - Windows 11

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 6 Posters 1.1k Views 4 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.
  • Juan de DironneJ Offline
    Juan de DironneJ Offline
    Juan de Dironne
    wrote on last edited by Juan de Dironne
    #1

    I am new to this Forum. I hope my question is well worded and in the right place.

    I use this code to test ftp upload with "QNetworkAccessManager" functions.

    main.cpp

    #include <QApplication>
    #include <QtWidgets>
    #include "MyMainWindow.h"
    
    
    int main (int nbArg, char* listArg[])
    {
      QApplication myApp(nbArg,listArg);
    
      MyMainWindow myWindow;
      myWindow.show();
    
      myApp.exec();
    }
    

    MyMainWindow.h

    #ifndef MYMAINWINDOW_H
    #define MYMAINWINDOW_H
    
    #include<QtWidgets>
    #include<QUrl>
    #include<QFile>
    #include<QtNetwork/QNetworkAccessManager>
    #include<QtNetwork/QNetworkReply>
    
    class MyMainWindow : public QMainWindow
    {
      Q_OBJECT
    
      public:
      MyMainWindow();
    
      public slots:
      void upload();
      void transfertFinished(QNetworkReply*);
      void displayError(QNetworkReply::NetworkError);
    
      private:
      QAction *m_actionUpload;
      QAction *m_actionQuit;
    
      private:
      QNetworkAccessManager *m_accesManager;
      QFile *m_fileTransfert;
      QNetworkReply *m_responseTransfert;
    };
    
    #endif // MYMAINWINDOW_H
    

    MyMainWindow.cpp

    #include "MyMainWindow.h"
    
    MyMainWindow::MyMainWindow()
    {
      m_accesManager = new QNetworkAccessManager(this);
    
      // Define Actions
      m_actionUpload  = new QAction("Upload",this);
      m_actionQuit    = new QAction("Quit",this);
    
      // Define Menu
      QMenu *fileMenu = menuBar()->addMenu("File");
      fileMenu->addAction(m_actionUpload);
      fileMenu->addAction(m_actionQuit);
    
      // Create Slot for Menu
      connect(m_actionUpload,SIGNAL(triggered()),this,SLOT(upload()));
      connect(m_actionQuit,SIGNAL(triggered()),qApp,SLOT(quit()));
    }
    
    
    void MyMainWindow::upload()
    {
      // Initialization
      QString localFileName   = "local_file.txt";
      QString distantFileName = "distant_file.txt";
      QUrl myUrl;
      QByteArray fileContent;
    
      // FTP Parameters
      myUrl.setScheme("ftp");
      myUrl.setHost("myServer.fr");
      myUrl.setPort(21);
      myUrl.setUserName("myLogin");
      myUrl.setPassword("myPassword");
      myUrl.setPath(distantFileName);
    
    
      // File Object
      m_fileTransfert = new QFile(localFileName,this);
    
      // If File Exist
      if(m_fileTransfert->exists())
      {
        // Create Request "Object" (from "object" URL)
        QNetworkRequest myRequest(myUrl);
    
        // Open Local File
        m_fileTransfert->open(QIODevice::ReadOnly);
        fileContent = m_fileTransfert->readAll();
    
        // Send the File via the Request object
        m_responseTransfert = m_accesManager->put(myRequest,fileContent);
      }
      else qDebug() << "File No Exist";
    }
    

    When I test for the first time, I have this error "qt.tlsbackend.ossl: Failed to load libssl/libcrypto"

    So I use "Qt Maintenance Tool" to install "OpenSSL 1.1.1q Toolkit".
    I then copy the installed "libcrypto-1_1-x64.dll" and "libssl-1_1-x64.dll" files into my executable folder.
    And testing the script again no more errors.
    But so far no file deposited on my server.

    And adding error handling with the code below

     // Send the File via the Request object
     m_responseTransfert = m_accesManager->put(myRequest,fileContent);
    
     // Slots
     connect(m_responseTransfert,SIGNAL(errorOccurred(QNetworkReply::NetworkError)),this,SLOT(displayError(QNetworkReply::NetworkError)));
    

    and

    void MyMainWindow::displayError(QNetworkReply::NetworkError errorFonc)
    {
      qDebug() << "Error : " << errorFonc;
      qDebug() << m_responseTransfert->errorString();
    }
    

    I obtain this error message
    Error : QNetworkReply::ProtocolUnknownError
    "Protocol "ftp" is unknown"

    What is wrong or missing in this code to get this error....?
    And as specified in the title I am under Windows 11 (this information is important in my opinion)
    And I am using "MSVC2019_64bit" compiler

    Jonas KvingeJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I have a feeling maybe its not included or something like that. code looks good.

      What do you get if you do
      qDebug() << m_accesManager->supportedSchemes();

      Juan de DironneJ 1 Reply Last reply
      1
      • Cobra91151C Offline
        Cobra91151C Offline
        Cobra91151
        wrote on last edited by
        #3

        @Juan-de-Dironne

        Hello!

        It seems Qt 6 does not have FTP support in Qt Network because they moved it to some plugin. More details you can get here: https://www.qt.io/blog/qt-network-in-qt-6
        Also, I recommend you to check out this Qt SCXML FTP Client Example: https://doc-snapshots.qt.io/qt6-dev/qtscxml-ftpclient-example.html using Qt 6. It could be useful for you.

        Juan de DironneJ 1 Reply Last reply
        1
        • mrjjM mrjj

          Hi
          I have a feeling maybe its not included or something like that. code looks good.

          What do you get if you do
          qDebug() << m_accesManager->supportedSchemes();

          Juan de DironneJ Offline
          Juan de DironneJ Offline
          Juan de Dironne
          wrote on last edited by
          #4

          @mrjj Thank you for taking the time to look and respond to me. I tried your code to see what schemes were supported and... FTP is not include :(
          So I must use QT 5 to do FTP...?

          1 Reply Last reply
          0
          • Cobra91151C Cobra91151

            @Juan-de-Dironne

            Hello!

            It seems Qt 6 does not have FTP support in Qt Network because they moved it to some plugin. More details you can get here: https://www.qt.io/blog/qt-network-in-qt-6
            Also, I recommend you to check out this Qt SCXML FTP Client Example: https://doc-snapshots.qt.io/qt6-dev/qtscxml-ftpclient-example.html using Qt 6. It could be useful for you.

            Juan de DironneJ Offline
            Juan de DironneJ Offline
            Juan de Dironne
            wrote on last edited by
            #5

            @Cobra91151 I had seen this code before but I found this code complex.
            So I searched for a code that seemed simpler to me and I came across this solution using "QNetworkAccessManager".
            But it seems it doesn't work as you say with QT 6 :(

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

              According to this post https://forum.qt.io/topic/136161/qt6-qnetworkrequest-and-ftp, they planned to move ftp support to plugin in Qt6 but never really done that because "little-to-no demand" and using libcurl is an alternative solution.

              1 Reply Last reply
              1
              • Juan de DironneJ Juan de Dironne

                I am new to this Forum. I hope my question is well worded and in the right place.

                I use this code to test ftp upload with "QNetworkAccessManager" functions.

                main.cpp

                #include <QApplication>
                #include <QtWidgets>
                #include "MyMainWindow.h"
                
                
                int main (int nbArg, char* listArg[])
                {
                  QApplication myApp(nbArg,listArg);
                
                  MyMainWindow myWindow;
                  myWindow.show();
                
                  myApp.exec();
                }
                

                MyMainWindow.h

                #ifndef MYMAINWINDOW_H
                #define MYMAINWINDOW_H
                
                #include<QtWidgets>
                #include<QUrl>
                #include<QFile>
                #include<QtNetwork/QNetworkAccessManager>
                #include<QtNetwork/QNetworkReply>
                
                class MyMainWindow : public QMainWindow
                {
                  Q_OBJECT
                
                  public:
                  MyMainWindow();
                
                  public slots:
                  void upload();
                  void transfertFinished(QNetworkReply*);
                  void displayError(QNetworkReply::NetworkError);
                
                  private:
                  QAction *m_actionUpload;
                  QAction *m_actionQuit;
                
                  private:
                  QNetworkAccessManager *m_accesManager;
                  QFile *m_fileTransfert;
                  QNetworkReply *m_responseTransfert;
                };
                
                #endif // MYMAINWINDOW_H
                

                MyMainWindow.cpp

                #include "MyMainWindow.h"
                
                MyMainWindow::MyMainWindow()
                {
                  m_accesManager = new QNetworkAccessManager(this);
                
                  // Define Actions
                  m_actionUpload  = new QAction("Upload",this);
                  m_actionQuit    = new QAction("Quit",this);
                
                  // Define Menu
                  QMenu *fileMenu = menuBar()->addMenu("File");
                  fileMenu->addAction(m_actionUpload);
                  fileMenu->addAction(m_actionQuit);
                
                  // Create Slot for Menu
                  connect(m_actionUpload,SIGNAL(triggered()),this,SLOT(upload()));
                  connect(m_actionQuit,SIGNAL(triggered()),qApp,SLOT(quit()));
                }
                
                
                void MyMainWindow::upload()
                {
                  // Initialization
                  QString localFileName   = "local_file.txt";
                  QString distantFileName = "distant_file.txt";
                  QUrl myUrl;
                  QByteArray fileContent;
                
                  // FTP Parameters
                  myUrl.setScheme("ftp");
                  myUrl.setHost("myServer.fr");
                  myUrl.setPort(21);
                  myUrl.setUserName("myLogin");
                  myUrl.setPassword("myPassword");
                  myUrl.setPath(distantFileName);
                
                
                  // File Object
                  m_fileTransfert = new QFile(localFileName,this);
                
                  // If File Exist
                  if(m_fileTransfert->exists())
                  {
                    // Create Request "Object" (from "object" URL)
                    QNetworkRequest myRequest(myUrl);
                
                    // Open Local File
                    m_fileTransfert->open(QIODevice::ReadOnly);
                    fileContent = m_fileTransfert->readAll();
                
                    // Send the File via the Request object
                    m_responseTransfert = m_accesManager->put(myRequest,fileContent);
                  }
                  else qDebug() << "File No Exist";
                }
                

                When I test for the first time, I have this error "qt.tlsbackend.ossl: Failed to load libssl/libcrypto"

                So I use "Qt Maintenance Tool" to install "OpenSSL 1.1.1q Toolkit".
                I then copy the installed "libcrypto-1_1-x64.dll" and "libssl-1_1-x64.dll" files into my executable folder.
                And testing the script again no more errors.
                But so far no file deposited on my server.

                And adding error handling with the code below

                 // Send the File via the Request object
                 m_responseTransfert = m_accesManager->put(myRequest,fileContent);
                
                 // Slots
                 connect(m_responseTransfert,SIGNAL(errorOccurred(QNetworkReply::NetworkError)),this,SLOT(displayError(QNetworkReply::NetworkError)));
                

                and

                void MyMainWindow::displayError(QNetworkReply::NetworkError errorFonc)
                {
                  qDebug() << "Error : " << errorFonc;
                  qDebug() << m_responseTransfert->errorString();
                }
                

                I obtain this error message
                Error : QNetworkReply::ProtocolUnknownError
                "Protocol "ftp" is unknown"

                What is wrong or missing in this code to get this error....?
                And as specified in the title I am under Windows 11 (this information is important in my opinion)
                And I am using "MSVC2019_64bit" compiler

                Jonas KvingeJ Offline
                Jonas KvingeJ Offline
                Jonas Kvinge
                wrote on last edited by Jonas Kvinge
                #7

                So I use "Qt Maintenance Tool" to install "OpenSSL 1.1.1q Toolkit".
                I then copy the installed "libcrypto-1_1-x64.dll" and "libssl-1_1-x64.dll" files into my executable folder.

                You need one of the TLS backends too, either qschannelbackend.dll or qopensslbackend.dll copied over to a directory called "tls". You only need libcrypto and libssl if you use the openssl backend instead of the schannel.

                Juan de DironneJ 1 Reply Last reply
                1
                • Jonas KvingeJ Jonas Kvinge

                  So I use "Qt Maintenance Tool" to install "OpenSSL 1.1.1q Toolkit".
                  I then copy the installed "libcrypto-1_1-x64.dll" and "libssl-1_1-x64.dll" files into my executable folder.

                  You need one of the TLS backends too, either qschannelbackend.dll or qopensslbackend.dll copied over to a directory called "tls". You only need libcrypto and libssl if you use the openssl backend instead of the schannel.

                  Juan de DironneJ Offline
                  Juan de DironneJ Offline
                  Juan de Dironne
                  wrote on last edited by
                  #8

                  @Jonas-Kvinge The problem was indeed not related to OpenSSL but to the version of QT.
                  With QT 5.15.2, the code allows to send the file to the Server.
                  With QT 6.4.2, the code returns an error "Protocol FTP is unknow".

                  But in which case I have to copy the TLS backends...? And the TLS directory you're talking about, where should it be...?

                  S 1 Reply Last reply
                  0
                  • Juan de DironneJ Juan de Dironne

                    @Jonas-Kvinge The problem was indeed not related to OpenSSL but to the version of QT.
                    With QT 5.15.2, the code allows to send the file to the Server.
                    With QT 6.4.2, the code returns an error "Protocol FTP is unknow".

                    But in which case I have to copy the TLS backends...? And the TLS directory you're talking about, where should it be...?

                    S Offline
                    S Offline
                    sidthatsme
                    wrote on last edited by
                    #9

                    @Juan-de-Dironne I had similar problems with FTP.
                    Qt 5 and FTP worked fine
                    With QT 6, I had to use ScXML to get my app to access FTP site.
                    It is possible but a lot of work is needed to get scxml to to access the FTP site of choosing

                    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