View Categories

SCP – copy files between servers – help and tips with examples

1 min read

SCP (Secure Copy Protocol) is essentially the cp command in Linux over SSH, used to copy files between remote and local servers.

Examples:

Copy a single file from your local server to a remote one. #

scp /home/billy/file1 user@remote-server-ip-address:/root/

The above example copies a file named file1 in directory /home/billy to a remote server into the remote servers /root directory.

Copy all files from a directory on your local server to a remote one. #

scp /home/billy/* user@remote-server-ip-address:/root/

The above example copies all files in the directory /home/billy/ to a remote server into the remote servers /root directory.

Copy all .iso files from your local server to a remote one. #

scp /home/billy/*.iso user@remote-server-ip-address:/root/

The above example copies all files with the extension .iso in directory /home/billy to a remote server into the remote servers /root directory.

Copy a single file from a remote server to the current directory on your local server #

scp user@remote-server-ip-address:/root/backup.gz .

The above example copies a file named backup.gz in directory /root/ on the remote server to your local server in whatever directory you are currently in (that is what the . at the end determines)

Copy a single file from a remote server to a directory on your local server #

scp user@remote-server-ip-address:/root/backup.gz /home.billy/backup/

The above example copies all files named in directory /root/ on the remote server to your local server in the directory /home/billy/backup/

Copy all files from a remote server to a directory on your local server #

scp user@remote-server-ip-address:/root/* /home.billy/backup/

The above example copies a file named backup.gz in directory /root/ on the remote server to your local server in the directory /home/billy/backup/

Other Tips #

  • You can use -r (after scp) to recursively copy all files and folders and files within folders.
  • you can use -P (after scp) to use a different SSH port
  • you can use -C to use a different encryption cypher if moving large files over a local network you might want to use arcfour256 rather than AES as it will speed things up by around 50% (Both the SSH client and server must support this) it is less secure but has less overhead.