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?

6
  • Mostly a dup of this - unix.stackexchange.com/questions/2690/…
    – Zoredache
    Jan 21, 2021 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, 2021 at 18:51
  • Thanks. Following an example there, I just tried `ssh [email protected] "unzip" < example_files.zip but it didn't work. Is there an example specific to zip archives?
    – StevieD
    Jan 21, 2021 at 18:55
  • @Zoredache Thanks for schooling me. Removed the invalid coment.
    – user143703
    Jan 21, 2021 at 19:12
  • 2
    It looks like the unzip that's included with busybox 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.
    – user143703
    Jan 21, 2021 at 19:37

1 Answer 1

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.

2
  • OK, thanks. Yeah, I think I'm just going to switch to tar archives instead.
    – StevieD
    Jan 21, 2021 at 19:00
  • Ugh. I actually have tools for stream-unpacking zip files but at several hundred MB, ...
    – joshudson
    Jan 22, 2021 at 2:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .