How is it possible to Zip, Download and Delete (ZDD) a file in WinSCP?

For example, your local dir is Desktop and your remote dir (the one in your server machine) is, say, /var/www/html and you want to zip and download a particular dir or file, and then you want it to be removed the moment the download was finished.

enter image description here

To further explain, in linux I could do, for example:

zip -r /var/www/html/dr.zip /var/www/html
scp /var/www/html/dr.zip USER@IP:/location
rm /var/www/html/dr.zip

I need similar thing for WinSCP yet I'm aware that the WinSCP download mechanism should be used and that it is different then the Nix scp utility.

My question:

Do you know a way to achieve this with WinSCP?

  • There's no generic magic solution to this. First we need to know what protocol you are using in WinSCP. – Martin Prikryl Apr 17 '17 at 18:37
  • Hi Martin! It is an honor to have you commenting on this! I use SFTP (on the native port). I know one can customize commands in WinSCP but it is unclear to me how one can customize a multi-row command set as I displayed above in the question. Moreover, it is unclear to me if the commands there must be written in Bash or Powershell(?) or if both are applicable. I humbly hope an answer will these points this too. – JohnDoea Apr 18 '17 at 2:00

There's no way to ZIP files over any file transfer protocol (SFTP, FTP, SCP or WebDAV). That's why there's no such function in WinSCP, as it cannot be implemented reliably.

Though, if you have a shell access to the server, you can use a shell command to ZIP the files. That's actually, what the Tar/GZip custom command does.

If you want it in one-go (zip-and-download), you would have to implement a more complex custom command/extension, that opens its own session for the download. It would be very similar to the Pack files to ZIP archive and upload it example. Except, that it would use Session.ExecuteCommand to execute zip (or similar) on the remote server.

You can write the extension in any language you like. PowerShell is just the most readily available Windows scripting language with good (native) .NET support. While it's doable in Bash too, you have to use a local Bash script (you cannot download a file using a remote Bash script). And there's no Bash in Windows by default.

  • I guess that if zip is problematic I could use tar.gz and then extract it easily in Win10 with either Winrar or Winzip. Also, If I understand corret, if I don't want to load a script file and want to paste the command to WinSCP, I could just copy one row command like the following and make it a custom command: zip -r /var/www/html/dr.zip /var/www/html && scp /var/www/html/dr.zip USER@IP:/location && rm /var/www/html/dr.zip. – JohnDoea Apr 18 '17 at 6:25
  • Ofcourse I might just replace zip to tar. – JohnDoea Apr 18 '17 at 6:25
  • 1
    I'm not sure you understand. zip is not more or less problematic than gzip/tar. It's the shell access that is the limitation. - And again, you cannot use remote Bash script/command to pull files from the server to Windows, so you cannot use the scp in the custom command, as that's executed on the server (of course, unless you run a SSH server on the local Windows machine). – Martin Prikryl Apr 18 '17 at 6:30
  • Oh, sorry I confused there. I meant that instead of scp there would be something else (the same thing WinSCP uses) to pull files into Windows). – JohnDoea Apr 18 '17 at 6:32
  • 1
    Again, there's no way to pull files using anything you can execute on the server. You have to use local script that opens its own connection for the download. See the links in my answer. – Martin Prikryl Apr 18 '17 at 6:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.