In order to copy files or directories from a remote server to your computer (or some other server) via SSH, you can use the scp (Secure Copy) command.
In order to do this you should first confirm you have SSH access to the remote server. E.g. if you run a command like the following, you should be able to connect to your server either via password authentication or via SSH keys:
> ssh username@your-server-ip
If you’re unable to do this, check out my guide Creating a SSH key connection with a server.
With SSH access confirmed, here’s an example command to copy a single file from some path on your remote server to a location on your computer:
scp username@remote_host:/path/to/file.txt /path/on/your/computer
Breakdown of the values in this command:
usernameis your username on the remote server.
remote_hostis the IP address or hostname of the remote server.
/path/to/fileis the path to the file on the remote server that you want to copy.
/path/on/your/computeris the path on your computer where you want to save the copied file.
As an example, if I had a file on my remote server at
/var/example/test.txt and I wanted to copy it to my computer’s Desktop, I’d run this command:
> scp email@example.com:/var/example/test1.txt ~/Desktop
To copy an entire directory, add the
-r (Recursive) flag:
scp -r username@remote_host:/path/to/directory /path/on/your/computer
As an example, if I had a directory on my remote server at
/var/example and I wanted to copy it to my computer’s Desktop, I’d run this command:
> scp firstname.lastname@example.org:/var/example ~/Desktop