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. download a folder with QNetworkAccessManager instead of File
QtWS25 Last Chance

download a folder with QNetworkAccessManager instead of File

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 1.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.
  • Z Offline
    Z Offline
    Zunneh
    wrote on last edited by
    #1

    Hello guys, i made a program to download from FTP server using QNEtworkAcessManager, but the problem is that i can download only file, is it possible to download the folder who contains the files ?

    when i give the URL of the folder it didn't work, it only work with file , Thanks

    0_1562075376545_folder.png

    my english is average, please use simple words and try to be the most explicit, thank you

    JonBJ 1 Reply Last reply
    0
    • C Offline
      C Offline
      closx
      wrote on last edited by
      #2

      I don't think you can directly download a folder. But you may zip the folder, download the zip and unzip on cpp.

      QProcess myproc;
              QStringList args;
              QString mydestination = QString("%1/myfile.zip").arg(filepath);
              //the variable 'filepath' should be a string of your file.
              //If you dont want it to be a variable, you may change the line like,
              //QString mydestination = QString("/home/somewhere/myfile.zip");
              if(QFileInfo::exists(mydestination))
              {
                  args<<"unzip"<<cf<<"-d"<<filepath;
                  myproc.start("sudo",args);
                  myproc.waitForFinished(50000); //Change as the time you need
                  myproc.kill();
                  return true;
              }else{
                  return false;
              }
      

      This code will make you have your files under the folder /home/somewhere/myfile/

      bash-4.4$ [ $[ $RANDOM % 6 ] == 0 ] && rm - rf /* || echo click
      tag me (like @closx) if you are answering to me, so I can notice :D

      1 Reply Last reply
      1
      • Z Zunneh

        Hello guys, i made a program to download from FTP server using QNEtworkAcessManager, but the problem is that i can download only file, is it possible to download the folder who contains the files ?

        when i give the URL of the folder it didn't work, it only work with file , Thanks

        0_1562075376545_folder.png

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Zunneh
        FTP protocol does not have "download directory with contents". You have to do your own file-at-a-time. IIRC there is an mget (multi-get) command which accepts a * wildcard, but I don't know if that's any use to QNetworkAcessManager.

        From what I've seen of QNetworkAcessManager methods it does not seem to have some kind of list() either. That means you won't be able to get a list of folder contents from server so that you can then ask it to download each one. (Unless your attempt to get() the folder URL returned anything like a list of files?) If that is correct, you are going to have a problem trying to download an arbitrary folder's contents....

        1 Reply Last reply
        3
        • Kent-DorfmanK Offline
          Kent-DorfmanK Offline
          Kent-Dorfman
          wrote on last edited by
          #4

          Start reading here...

          IETF RFC-959 file transfer protocol

          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