12

I frequently transfer large directories over scp and it would be sweet if I could somehow compress the directory, send it, and decompress it all in one.

Is something like this possible?

3 Answers 3

31

How about using rsync instead with the -z option enabled for compression?

rsync -az --progress source_dir/* remote_host:/destination_dir

This also has the added benefit that if the file already exists and has not changed on the destination, it will not be transferred.

0
7

Thanks to @johnshen64's answer, I was able to come up with something quite nice

tar -zc path/to/source | ssh user@remote tar -zxC path/to/destination

Unfortunately, this doesn't show progress as it transfers. I have noticed incredible speed improvements using this method.

If anyone know how to show progress for a transfer like this, I'd greatly appreciate the help :)

2
  • 1
    Insert pv between tar and ssh. May 7, 2012 at 18:38
  • This is great if you don't have rsync available Sep 29, 2013 at 0:50
2

well, i would use tar instead

tar cf - directory | ssh server 'tar xf -'

you can add v to verify.

zip should be the same, but tar is more robust for linux in my opinion.

2
  • +1 thanks for your help; this got me half way there. I was able to come up with a solution that doesn't use the cryptic - character, also uses gzip compression and allows to target a destination directory.
    – macek
    May 7, 2012 at 17:50
  • @macek: Note that f - might be required on other operating systems, since most tar versions will try to read from a tape drive otherwise. Reading from stdin by default is GNU-specific. May 7, 2012 at 18:39

You must log in to answer this question.

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