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 username@your.server.example.com:/path/to/source/folder /path/to/local/destination 

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

 scp -r username@your.server.example.com:/path/to/source/folder /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 username@your.server.example.com:/path/to/source/folder /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 username@your.server.example.com:/var/www/html/media/videos /home/user/downloads

Leave a comment

Your email address will not be published. Required fields are marked *