How to Copy Files from Server to Server with SSH on the Command Line
The SCP command is typically employed to perform file copies through OpenSSH, although SFTP (secure FTP) is also supported. To copy a file from one Linux server to another, open a command line terminal and follow the example below:
scp /local_directory/local_file username@hostname_or_IP_address:~/remote_directory
or to copy a file from the remote Linux server to the local Linux server:
scp username@hostname_or_IP_address:/remote_directory/remote_file /local_directory
A few notes for clarification:
Local Directory – This refers to a directory on the local server.
Local File – A file, which will be copied from the local server to a remote server.
Username – The name of the account whose credentials will be used to login to the remote server.
Hostname – The DNS or hostname of the remote server.
Remote Directory – The destination directory on the remote server for the file to be copied.
Remote File – A file located on the remote server that will be copied to the local server.
Notice that SCP uses the simple “SCP From To" syntax to copy files. When you start an SSH session using either of the commands above, SSH will request the password for the account username issued in the command before the session is established and the file copy is completed.