Secure copy or SCP allows secure transferring of files between a local host and a remote host or between two remote hosts. It uses the same authentication and security as the Secure Shell (SSH) protocol from which it is based.
Basic secure copy examples:
Copy file from a remote host to local host:
$ scp username@from_host:file.txt /local/directory/
Copy file from local host to a remote host:
$ scp file.txt username@to_host:/remote/directory/
Copy directory from a remote host to local host:
$ scp -r username@from_host:/remote/directory/ /local/directory/
Copy directory from local host to a remote host:
$ scp -r /local/directory/ username@to_host:/remote/directory/
Copy file from remote host to remote host:
$ scp username@from_host:/remote/directory/file.txt username@to_host:/remote/directory/
— Example: scp -r email@example.com:/var/www/html/ /home/hydn/backups/test/
— Host can be IP or domain name. Once you click return, you will be prompted for SSH password.
— Although this page covers Linux OS, the instructions will also work for Mac using “Terminal”. You can also use WinSCP to accomplish this on a Windows PC/server.
— When copying a source file to a target file which already exists, scp will replace the contents of the target file. So be careful.
— SCP is faster and more secure than FTP.
-r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.
-C – Compression enable. Passes the -C flag to ssh to enable compression.
-l limit – Limits the used bandwidth, specified in Kbit/s.
-o ssh_option – Can be used to pass options to ssh in the format used in ssh_config.
-P port – Specifies the port to connect to on the remote host. Note that this option is written with a capital ‘P’.
-p Preserves modification times, access times, and modes from the original file.
-q Quiet mode: disables the progress meter as well as warning and diagnostic messages from ssh.
-v Verbose mode. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.