How to Copy a File from/to a Remote Server
scp command is being used to copy files from a remote server to a local machine and vice versa. It uses ssh to do secure file transfer.
1. Copy a file from a remote server to a local machine
It will ask the password for remote user
scp [email protected]:/remote/path/to/file /local/path
* symbol can be used to copy multiple files by pattern like w3docs* which will copy w3docs.sql, w3docs1.pdf and etc.
2. Copy a directory from a remote server to a local machine
-r should be used for directories
scp -r [email protected]:/remote/path/to/directory /local/path
3. Copy a file from a local machine to a remote server
scp /local/file/path username@example:/remote/path
4. Copy a directory from a local machine to a remote server
-r should be used for directories
scp -r /local/directory/path username@example:/remote/directory/path
5. Copy files by using RSA keys
If there is an identity key (RSA) instead of password than -i should be added
scp -i /path/to/key [email protected]:/remote/path/to/file /local/path