0

I've got a working process to upload a zip file to my FTP server. I'd like my program to unzip it, rather than me having to log in to my hosting file manager and manually extract it. I've been searching online and through the Indy documentation, but haven't had any success.

    function UnzipUploadedFile: Boolean;
    begin
      Result := False;
      //i don't know what to do next...
    end;

    function UploadZippedMediaAssets (sFile: String; lblEcho: TLabel; nFTP: TIdFTP): Boolean;
    var s: String;
    begin
      Result := False;

      if ConnectToFTPServer (nFTP, False, s) then
        begin
          Talk (lblEcho, 'FTP connected to ' + nFTP.Username + '@' + nFTP.Host);
        end
      else
        begin
          Talk (lblEcho, s);
          Exit;
        end;

     try
        nFTP.ChangeDir('/');
        nFTP.ChangeDir('upload/');
        nFTP.TransferType := ftBinary;
        Talk (lblEcho, 'uploading ' + sFile);
        nFTP.Put (sFile, ExtractFileName(sFile), False, -1);

        Talk (lblEcho, 'unzipping ' + ExtractFileName(sFile));
        //this is where I'm stuck
        Result := UnzipUploadedFile;
      except on e:Exception do
        begin
          Talk (lblEcho, sFile + ' failed: ' + e.Message);
        end;
      end;
    end;

Any direction as to what components and/or code is necessary to get this done would be greatly appreciated!

skippix
  • 17
  • 1
  • 6
  • 1
    There's no API in the FTP protocol to un-ZIP a file on a server. See also [Can we unzip file in FTP server using C#](https://stackoverflow.com/q/45935372/850848). – Martin Prikryl Dec 13 '17 at 15:50
  • You can't unzip a file remotely. You will have to unzip it locally and then upload the contents instead of the zip itself. If you are concerned about transfer size and bandwidth usage for uploading the unzipped data, the FTP protocol does support compression while transferring data. – Remy Lebeau Dec 13 '17 at 17:02
  • Thanks! I'll explore the SSH option and ask another question if I get stuck there. @RemyLebeau , I was hoping to avoid the overhead of uploading anywhere from 20-1000 files vs one possibly large zip file. I'll keep experimenting and testing. – skippix Dec 14 '17 at 15:58

0 Answers0