1

I have files in a .zip archive I want to upload to a remote server over ssh. I want to avoid uploading and then unzipping because the remote server has limited space.

I could unzip the archive locally and then upload the unzipped files. That seems wasteful and then I have to do some cleanup.

Ideally, I'd like the files that get unpacked from the archive to get sent directly to the remote server instead of saved to the local host. Is there a way to do this over ssh?

StevieD
  • 474
  • 5
  • 17
  • Mostly a dup of this - https://unix.stackexchange.com/questions/2690/how-to-redirect-output-of-wget-as-input-to-unzip – Zoredache Jan 21 '21 at 18:50
  • 1
    @yoonix zip is 'special' and doesn't work from stdin as easily because of the way the archive is formated. Not sure that superuser answer helps since it is mostly about tar archives. – Zoredache Jan 21 '21 at 18:51
  • Thanks. Following an example there, I just tried `ssh admin@example.org "unzip" < example_files.zip but it didn't work. Is there an example specific to zip archives? – StevieD Jan 21 '21 at 18:55
  • @Zoredache Thanks for schooling me. Removed the invalid coment. –  Jan 21 '21 at 19:12
  • 2
    It looks like the unzip that's included with [busybox](https://busybox.net/) can handle stdin just fine. If you can install that, you can run `busybox unzip -` on the ssh command line and it should work. I think your idea of just moving to tar is a better option though. –  Jan 21 '21 at 19:37
  • only way I managed to do it a couple years ago when I had this problem was to extract the list of files and use `-p` on each of them in a script. `-p` allows you to dump *one* file to stdout so the script does it one at a time. Not an ideal long-term situation. –  Jan 22 '21 at 00:45

1 Answers1

2

Sending stdin/stdout over ssh is covered elsewhere, but because that is tricky with zip files, here's an alternative with sshfs:

sshfs user@host /mnt/path
cd /mnt/path
unzip /tmp/foobar.zip
cd /
fusermount -u /mnt/path

Your mileage may very, because sshfs is has various problems.

If you can change your original files to something like gzip, which is one gz file per source file, that can easily be redirected over ssh, including fancy progress viewing with pv.

Halfgaar
  • 7,921
  • 5
  • 42
  • 81