How to copy multiple files over SSH

Sometimes we need to move a collection of files form one server to another server. It is because maybe we are updating our server space or changing storage provider for media files for our server.

If we have SSH access to the server , we can use a cli tool called SCP. SCP stands for secure copy.

SCP has the following syntax:

scp /path/to/local/destination 

To make it work for folder we have use the -r option. So it becomes :

 scp -r /path/to/local/destination 

This will prompt for ssh username and password . If you use ssh key to access the server then we can provide the key file as following:

scp -i /path/to/sshkeyfile -r /path/to/local/destination

Imagine we have to download the video folder form our nginx webserver to our local machine’s downloads folder , the command will look something similar to this :

scp -i /path/to/sshkeyfile -r /home/user/downloads