Transfering Directory Trees via ssh

To transfer a whole directory tree from one host to another including file attributes using ssh as transport channel:

tar czvf - <directory> | ssh <host> "cd <destination dir>; tar xzvf -"

This pipe consists of a tar command which writes it's output data to stdout where it is piped to stdin of ssh. ssh connects to the <host> and fist changes the working directory there to <destination dir>. Then it starts a tar extraction command and passes the data it gets from the local host over to it. While receiving the data tar extracts and restores the directory tree at the remote host.

To unpack a remotely stored tar ball to the local machine without making a local copy of the tar file:

ssh <host> "cat <tar file>" | tar xzvf -

To compress and copy a locally stored file to a remote machine without storing the compressed file locally:

gzip -c <source_file> | ssh <host> "cat > <destination_file>"

linux logo Powered by Apache
This site maintained by:
My public PGP key
last updated: 2006-12-18 Valid CSS! Valid XHTML 1.0 Strict