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. Are we able to delete files on FTP server using QT?
Forum Updated to NodeBB v4.3 + New Features

Are we able to delete files on FTP server using QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 4 Posters 957 Views 2 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.
  • K Offline
    K Offline
    KidTrent
    wrote on last edited by KidTrent
    #1

    I read an article that this was not supported by QNetworkAccessManager, but this was back in 2013. Has this changed at all in the last 8 years? When I try to issue a delete using QNetworkAccessManager::deleteResource, I get an error saying: "Protocol 'ftp' is unknown".

    So I guess my question is... is there another way?

       QUrl url;
       url.setHost(m_ftp_host);
       url.setPort(m_ftp_port);
       url.setUserName(m_ftp_username);
       url.setPassword(m_ftp_password);
       url.setScheme("ftp");
       url.setPath(ftp_absolute_file_path);
    
       QNetworkAccessManager* manager = new QNetworkAccessManager();
       const QNetworkRequest request(url);
       QNetworkReply* reply = manager->deleteResource(request);
    
       connect(reply, &QNetworkReply::errorOccurred, [=] {
           QString errorMessage   = reply->errorString();
           qDebug() << "Error: " << errorMessage;
       });
    
       connect(manager, &QNetworkAccessManager::finished, this, &FileUploadWorker::onDeleteComplete);
    
    Pl45m4P artwawA 2 Replies Last reply
    0
    • K KidTrent

      I read an article that this was not supported by QNetworkAccessManager, but this was back in 2013. Has this changed at all in the last 8 years? When I try to issue a delete using QNetworkAccessManager::deleteResource, I get an error saying: "Protocol 'ftp' is unknown".

      So I guess my question is... is there another way?

         QUrl url;
         url.setHost(m_ftp_host);
         url.setPort(m_ftp_port);
         url.setUserName(m_ftp_username);
         url.setPassword(m_ftp_password);
         url.setScheme("ftp");
         url.setPath(ftp_absolute_file_path);
      
         QNetworkAccessManager* manager = new QNetworkAccessManager();
         const QNetworkRequest request(url);
         QNetworkReply* reply = manager->deleteResource(request);
      
         connect(reply, &QNetworkReply::errorOccurred, [=] {
             QString errorMessage   = reply->errorString();
             qDebug() << "Error: " << errorMessage;
         });
      
         connect(manager, &QNetworkAccessManager::finished, this, &FileUploadWorker::onDeleteComplete);
      
      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @KidTrent said in Are we able to delete files on FTP server using QT?:

      "Protocol 'ftp' is unknown".

      Note: This feature is currently available for HTTP only, performing an HTTP DELETE request.

      (from: https://doc.qt.io/qt-5/qnetworkaccessmanager.html#deleteResource)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2
      • K KidTrent

        I read an article that this was not supported by QNetworkAccessManager, but this was back in 2013. Has this changed at all in the last 8 years? When I try to issue a delete using QNetworkAccessManager::deleteResource, I get an error saying: "Protocol 'ftp' is unknown".

        So I guess my question is... is there another way?

           QUrl url;
           url.setHost(m_ftp_host);
           url.setPort(m_ftp_port);
           url.setUserName(m_ftp_username);
           url.setPassword(m_ftp_password);
           url.setScheme("ftp");
           url.setPath(ftp_absolute_file_path);
        
           QNetworkAccessManager* manager = new QNetworkAccessManager();
           const QNetworkRequest request(url);
           QNetworkReply* reply = manager->deleteResource(request);
        
           connect(reply, &QNetworkReply::errorOccurred, [=] {
               QString errorMessage   = reply->errorString();
               qDebug() << "Error: " << errorMessage;
           });
        
           connect(manager, &QNetworkAccessManager::finished, this, &FileUploadWorker::onDeleteComplete);
        
        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @KidTrent Currently HTTP, FTP and local file URLs are supported for uploading and downloading.

        https://forum.qt.io/topic/127393/are-we-able-to-delete-files-on-ftp-server-using-qt

        However, actual implementing is not clear to me atm. How Qt handles choice between active/passive ftp? I don't know.

        From my experience, you should experiment with sending control words to the server - set user name and password and so on, then try custom request with control work, like "PASV" or "TYPE A" or "TYPE I" and then analyse replies.

        Or, if you're willing to consider the learnings done by others, there is quite old library you can take a look at https://github.com/qt/qtftp

        For more information please re-read.

        Kind Regards,
        Artur

        VRoninV 1 Reply Last reply
        1
        • artwawA artwaw

          @KidTrent Currently HTTP, FTP and local file URLs are supported for uploading and downloading.

          https://forum.qt.io/topic/127393/are-we-able-to-delete-files-on-ftp-server-using-qt

          However, actual implementing is not clear to me atm. How Qt handles choice between active/passive ftp? I don't know.

          From my experience, you should experiment with sending control words to the server - set user name and password and so on, then try custom request with control work, like "PASV" or "TYPE A" or "TYPE I" and then analyse replies.

          Or, if you're willing to consider the learnings done by others, there is quite old library you can take a look at https://github.com/qt/qtftp

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @artwaw said in Are we able to delete files on FTP server using QT?:

          you can take a look at https://github.com/qt/qtftp

          Qt FTP has been discontinued a long time ago.
          QNAM dropped the FTP support by design and I don't see it getting it back.
          There are plenty of well established libraries to handle ftp (like libcurl), you don't need to use an obsolete library with no support

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          artwawA 1 Reply Last reply
          2
          • VRoninV VRonin

            @artwaw said in Are we able to delete files on FTP server using QT?:

            you can take a look at https://github.com/qt/qtftp

            Qt FTP has been discontinued a long time ago.
            QNAM dropped the FTP support by design and I don't see it getting it back.
            There are plenty of well established libraries to handle ftp (like libcurl), you don't need to use an obsolete library with no support

            artwawA Offline
            artwawA Offline
            artwaw
            wrote on last edited by
            #5

            @VRonin said in Are we able to delete files on FTP server using QT?:

            QNAM dropped the FTP support by design and I don't see it getting it back.

            This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html

            For more information please re-read.

            Kind Regards,
            Artur

            Pl45m4P 1 Reply Last reply
            1
            • artwawA artwaw

              @VRonin said in Are we able to delete files on FTP server using QT?:

              QNAM dropped the FTP support by design and I don't see it getting it back.

              This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @artwaw said in Are we able to delete files on FTP server using QT?:

              This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html

              Why? FTP is supported, but AFAIK you can't delete stuff on the FTP server with a QNetworkRequest (using the FTP protocol)


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              artwawA 1 Reply Last reply
              1
              • Pl45m4P Pl45m4

                @artwaw said in Are we able to delete files on FTP server using QT?:

                This page needs updating then... https://doc.qt.io/qt-5/qtnetwork-programming.html

                Why? FTP is supported, but AFAIK you can't delete stuff on the FTP server with a QNetworkRequest (using the FTP protocol)

                artwawA Offline
                artwawA Offline
                artwaw
                wrote on last edited by
                #7

                @Pl45m4 I don't know why but apparently @VRonin knows it has been dropped:

                @VRonin said in Are we able to delete files on FTP server using QT?:

                QNAM dropped the FTP support by design and I don't see it getting it back.

                For more information please re-read.

                Kind Regards,
                Artur

                Pl45m4P 1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  My bad. You can do very basic operations (upload and download) using FTP and QNAM. I don't consider this to be "supprting" ftp as even the most simple of operations (listing files) is not supported.
                  When the FTP module was dropped from Qt Network I considered it as the sign I should look to an external library for that

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  artwawA 1 Reply Last reply
                  3
                  • artwawA artwaw

                    @Pl45m4 I don't know why but apparently @VRonin knows it has been dropped:

                    @VRonin said in Are we able to delete files on FTP server using QT?:

                    QNAM dropped the FTP support by design and I don't see it getting it back.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @artwaw

                    IIRC this example (https://doc.qt.io/qt-5/qtnetwork-download-example.html) works (or worked at least with 5.15) using FTP.
                    I'm a bit confused :)

                    Edit:

                    @VRonin said in Are we able to delete files on FTP server using QT?:

                    My bad. You can do very basic operations (upload and download) using FTP and QNAM. I don't consider this to be "supprting" ftp as even the most simple of operations (listing files) is not supported.

                    Not confused anymore ;-)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    2
                    • VRoninV VRonin

                      My bad. You can do very basic operations (upload and download) using FTP and QNAM. I don't consider this to be "supprting" ftp as even the most simple of operations (listing files) is not supported.
                      When the FTP module was dropped from Qt Network I considered it as the sign I should look to an external library for that

                      artwawA Offline
                      artwawA Offline
                      artwaw
                      wrote on last edited by
                      #10

                      @VRonin Thank you for clarifying!

                      For more information please re-read.

                      Kind Regards,
                      Artur

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved