← Other topics

Copy files from a server to your computer using command line / SSH SCP

Video Notes

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.

Copy a file

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:

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 root@167.99.151.173:/var/example/test1.txt ~/Desktop

Copy a directory

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 root@167.99.151.173:/var/example ~/Desktop

Unlock all the notes for $4

No subscriptions, no auto-renewals.

Just a simple one-time payment that helps support my free, to-the-point videos without sponsered ads.

Unlocking gets you access to the notes for this video plus all 200+ guides on this site.

Your support is appreciated. Thank you!

Payment Info

/
$4 6 months
$25 forever
Please check the form for errors
Questions? help@codewithsusan.com
← Other topics