How to gzip a directory, transfer via scp, and decompress in one command?

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?


Solution 1:

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.

Solution 2:

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 :)

Solution 3:

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.