Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Qt6 QNetworkaccessmanager FTP connection and manipulation

Qt6 QNetworkaccessmanager FTP connection and manipulation

Scheduled Pinned Locked Moved Unsolved Qt 6
6 Posts 4 Posters 2.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.
  • T Offline
    T Offline
    Thiago Dias
    wrote on 29 Mar 2021, 18:22 last edited by
    #1

    Good afternoon,
    and then guys I have a serious problem, I need to make an application in QT 6, however, I have to connect to an FTP server with a user and password, right after, I need to list all the files in a certain directory so that the user can download. I read the documentation, tested several codes but it doesn't connect and reports the following error QNetworkRequest :: ProtocolUnkwonError. Would anyone have a link with content so that I can study about FTP connections in QT 6?

    A 1 Reply Last reply 29 Mar 2021, 18:38
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Mar 2021, 18:32 last edited by
      #2

      Hi and welcome to devnet,

      The differences between Qt 5 and Qt 6 with regard to the network API are not that big so following the Qt 5 related threads you may find here will still be relevant.

      What exactly did you try ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Thiago Dias
        29 Mar 2021, 18:22

        Good afternoon,
        and then guys I have a serious problem, I need to make an application in QT 6, however, I have to connect to an FTP server with a user and password, right after, I need to list all the files in a certain directory so that the user can download. I read the documentation, tested several codes but it doesn't connect and reports the following error QNetworkRequest :: ProtocolUnkwonError. Would anyone have a link with content so that I can study about FTP connections in QT 6?

        A Offline
        A Offline
        artwaw
        wrote on 29 Mar 2021, 18:38 last edited by
        #3

        @Thiago-Dias Please post the parts relevant to building network requests.

        For more information please re-read.

        Kind Regards,
        Artur

        1 Reply Last reply
        0
        • T Offline
          T Offline
          Thiago Dias
          wrote on 30 Mar 2021, 19:49 last edited by
          #4

          #include "principalwindow.h"
          #include "ui_principalwindow.h"
          #include <QMessageBox>
          #include <QChartView>
          #include <QtCharts/QLineSeries>

          #include <QJsonArray>
          #include <QJsonDocument>
          #include <QJsonObject>
          #include <QJsonValue>

          #include <QDebug>

          QNetworkReply *reply;

          PrincipalWindow::PrincipalWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::PrincipalWindow)
          {
          ui->setupUi(this);

          QObject::connect(json, SIGNAL(finished(QNetworkReply*)),
                               this, SLOT(jsonRequestFinished(QNetworkReply*)));
          this->jsonRequest();
          
          QObject::connect(ftp, SIGNAL(finished(QNetworkReply*)),
                           this, SLOT(ftpRequestFinished(QNetworkReply*)));
          
          this->ftpRequest();
          

          [...]

          }

          PrincipalWindow::~PrincipalWindow()
          {
          delete ui;
          }

          void PrincipalWindow::ftpRequest(){
          QUrl url;
          url.setScheme("ftp");
          url.setHost("ftp.gazetadaprovincia.jor.br");
          url.setPort(21);
          url.setUserName("user");
          url.setPassword("password");
          QNetworkReply* reply = ftp->get(QNetworkRequest(url));
          QByteArray data = reply->readAll() ;
          qDebug() << data ;

          }

          void PrincipalWindow::ftpRequestFinished(QNetworkReply* reply){
          if(reply->error() == QNetworkReply::NoError) {

              QString strReply = (QString)reply->readAll();
              qDebug() << strReply;
          
          } else {
              qDebug() << reply->error();
          }
          

          }

          A 1 Reply Last reply 31 Mar 2021, 19:52
          0
          • T Thiago Dias
            30 Mar 2021, 19:49

            #include "principalwindow.h"
            #include "ui_principalwindow.h"
            #include <QMessageBox>
            #include <QChartView>
            #include <QtCharts/QLineSeries>

            #include <QJsonArray>
            #include <QJsonDocument>
            #include <QJsonObject>
            #include <QJsonValue>

            #include <QDebug>

            QNetworkReply *reply;

            PrincipalWindow::PrincipalWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::PrincipalWindow)
            {
            ui->setupUi(this);

            QObject::connect(json, SIGNAL(finished(QNetworkReply*)),
                                 this, SLOT(jsonRequestFinished(QNetworkReply*)));
            this->jsonRequest();
            
            QObject::connect(ftp, SIGNAL(finished(QNetworkReply*)),
                             this, SLOT(ftpRequestFinished(QNetworkReply*)));
            
            this->ftpRequest();
            

            [...]

            }

            PrincipalWindow::~PrincipalWindow()
            {
            delete ui;
            }

            void PrincipalWindow::ftpRequest(){
            QUrl url;
            url.setScheme("ftp");
            url.setHost("ftp.gazetadaprovincia.jor.br");
            url.setPort(21);
            url.setUserName("user");
            url.setPassword("password");
            QNetworkReply* reply = ftp->get(QNetworkRequest(url));
            QByteArray data = reply->readAll() ;
            qDebug() << data ;

            }

            void PrincipalWindow::ftpRequestFinished(QNetworkReply* reply){
            if(reply->error() == QNetworkReply::NoError) {

                QString strReply = (QString)reply->readAll();
                qDebug() << strReply;
            
            } else {
                qDebug() << reply->error();
            }
            

            }

            A Offline
            A Offline
            artwaw
            wrote on 31 Mar 2021, 19:52 last edited by
            #5

            This looks properly. Strange.
            Two things I'd try:

            • first, check if the ftp scheme is supported at all (I assume the ftp is of type QNetworkAccessManager): qDebug() << ftp->supportedSchemes();
            • when setting options for QUrl add mode as TolerantMode (however this is highly unlikely to solve the problem)

            Apart from that I am out of ideas for now.

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply
            0
            • JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 28 Apr 2022, 14:12 last edited by JonB
              #6

              See QT6 Protocol "ftp" is unknown and https://www.qt.io/blog/qt-network-in-qt-6.

              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