Copy files/folders accross a network in Linux using ssh, tar, scp and rsync.

SCP or secure copy is probably the easiest of all the methods, its is designed as a replacement for rcp, which was a quick copy of cp with network funcationability. Before scp does any copying it first connects via ssh. SCP encrypts data over your network connection, but by using the -C switch you can compress the data before it goes over the network. This can significantly decrease the time it takes to copy large files.

scp -r directory user@server:~/

or default port

scp "-P 7787" -r directory user@server:~/

TAR is usually used for achiving applications, but what we are going to do in this case is tar it then pipe it over an ssh connection. TAR handles large file trees quite well and preserves all file permissions, and works quite well with symlinks.

tar -czf - directory | ssh -p 7787 user@server tar -xzf - -C .

or default port

tar -czf - directory | ssh user@server tar -xzf - -C .


tar -xzf - directory | ssh user@server "cat > /directory/tarball.tar.gz"


dpkg -l | ssh user@server "cat > /directory/dpkg-list.txt"

RSYNC speciality lies in its ability to analyse files and only copy the changes made to files rather than all files. This can lead to enormous improvements when copying a directory tree a second time.

rsync -avze "ssh -p 7787" directory user@server:~/

or default port

rsync -avze ssh directory user@server:~/

Leave a Reply

Your email address will not be published. Required fields are marked *