Copy file from a remote host to local host SCP example:
scp username@from_host:file.txt /local/directory/
Copy file from local host to a remote host SCP example:
scp file.txt username@to_host:/remote/directory/
Copy all files and folders from a directory on a local host to a remote host
scp -rp /local-host/www/website-name/* firstname.lastname@example.org:/remote-host/website-name/public_html/
The same command as above, but for Amazon AWS EC2 remote hosts
scp -rp -i /LightsailDefaultPrivateKey-eu-west-2.pem /local-host/website-name/public_html/* email@example.com:/remote-host/www/website-name/
You must first upload and reference your AWS EC2 private key as shown above. Furthermore, in order for this to work you must set the correct permissions to your PEM key using the following command
chmod 400 /awskeyfile.pem
Copy directory from a remote host to local host SCP example:
scp -r username@from_host:/remote/directory/ /local/directory/
Copy directory from local host to a remote hos SCP example:
scp -r /local/directory/ username@to_host:/remote/directory/
Copy file from remote host to remote host SCP example:
scp username@from_host:/remote/directory/image.jpg username@to_host:/remote/directory/
SCP Linux options:
–r Recursively copy entire directories. Note that this 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. Print debugging messages about progress. This is helpful in debugging connection, authentication, and configuration problems.