Recently I wanted to copy some files between two servers. Yes I haven’t done this before in a terminal session. Usually I utilize GUI powered tools to do the job via SFTP.

I decided to do this with SCP because it’s way faster than SFTP, http://www.kontrolit.net/glossary/ sais:

SFTP, Secure File Transfer Program similar to ftp, but performs all operations over an encrypted SSH transport, thus gaining the features of public key encryption and compression.

SCP, Secure Copy is a program to copy files between hosts on a network. It too uses SSH for authentication and data transfer, thus gaining the features of strong authentication and secure encrypted communications.

Some googleing brought me to this site: http://www.examplenow.com/scp/ Instead of bookmarking it I share the information with you. These are some methods how you can copy files or whole directories:

Copy myfile.txt from myserver1.com to myserver2.com:

scp user1@myserver1.com:/tmp/myfile.txt user2@myserver2.com:/tmp/dir/myfile.txt

Copy file from remote server myserver.com to /tmp/mydir:

scp username@myserver.com:myfile.txt /tmp/mydir

Copy remote file myfile.txt from /tmp/mydir to current directory:

scp myfile.txt user@myserver.com:/tmp/mydir

Copy file using port 5533 to current directory:

scp -P 5533 user@myserver.com:/home/user/myfile.txt .

Copy the local directory mydir to /tmp/remotedir on myserver.com:

scp -r mydir user@myserver.com:/tmp/remotedir

Copy files from myserver.com to current directory and set the bandwidth limit to 50 Kbit/s:

scp -l 50 user@myserver.com:/home/user/* .

Use blowfish encription and compression to transfer files, this will increase speed on low bandwith connections, but also add extra overhead on the CPU:

scp -c blowfish -C myfile.txt user@myserver.com:~

Copy multiple files from remote host to current directory:

scp user@myserver.com:~/\{myfile1.txt,myfile2.txt\} .

Use blowfish encription to speed up transfer rate, copy myfile.txt to myserver.com in users home directory:

scp -c blowfish myfile.txt user@myserver.com:~