An SSH session is like a portal on another machine. If you’re used to working with Windows, you’ll know how easy it is to transfer files from one location to another. Just drag and drop! No text commands, no authentication, none of that.
However, sometimes you will need to download an SSH file to your local desktop, such as if you are using one of our managed VPS hosting services. And there is no simple command from the SSH terminal itself to do this. The two environments are too far apart. However, we have a dedicated tool called “SCP” which stands for “Secure Copy” that is made precisely for these types of situations.
Here’s how it works. First, we have a file on the remote server called filetodownload.txt, as shown here
Let’s transfer this file from Linux to our Windows desktop.
Step 1: Gather
the necessary information To transfer a file from a remote server via SSH
using SCP, we need the following information
- Login credentials: username, server name or IP address and password
- port number for SSH connections
- file on the remote server The path
The path to the
download location You should already have the login credentials when you connect to the server using PuTTY, or some other tool, so we won’t go here. Learn more about basic PuTTY commands.
As for the port number, you will need to know which SSH server port your VPS is listening on. It will be 22 (the default port) or you will be given when you order your VPS from your hosting provider.
To get the full path to the file you want to transfer, enter the “pwd” command in the CLI of the remote server while the file is in its current directory. This will give you the name of the folder as well
Now simply add the file
name to the path you get and you’re done.
As for the path to the download location, that’s something you have to get on your own!
Step 2: Create
the SCP command
The SCP command looks like this
:scp -P [port number] [user name]@[server or IP name]: [path to file on server] [path to file on local computer]
Replace the bold sections with the information you collected in step 1. For example, the command used for this example is
:scp -P 7022 firstname.lastname@example.org:/root/filetodownload.txt C:Users[UserName]Desktop
Step 3: Run the Open
a Command Line command in Windows. Windows 10 already has SCP installed by default. For this example, we’ll use the Windows PowerShell tool to run the commands. The color contrasts with yellow, and the syntax highlighting is a nice change from the monotonous command line.
Pasting the above command into the local command line editor gives us:
As you can see, you must first confirm the connection using the RSA fingerprint of the remote server. Once you type “yes”, it will be permanently added to the “known_hosts” file.
The file “known_hosts” in Windows is located in:
C:Users[User Name].sshknown_hosts Replace [
User Name] with your own Windows user name. It’s a file with no extension,
An editor like Notepad++ is great for this type of files. Each RSA fingerprint is added on a new line. This allows you to easily delete them by deleting an entire line at a time if you ever need to delete an entry.
Once you provide your password in the message, the file is downloaded immediately, as shown here:
And that’s it! Navigate to the location you specified in your SCP command and the file should be visible.
SCP is the most direct way to transfer and download files from remote servers to local systems. It makes use of the same SSH protocols, so the connection is encrypted to the end, making it immune to man-in-the-middle attacks. Hopefully, this tutorial will help you use it in an efficient and easy way. If you use one of our managed Linux VPS services and have a problem with SCP or need more information about it, feel free to contact our 24×7 Linux server support, which comes included with your hosting plan.
If this tutorial helped you move files from your remote server to your local machine, you might consider sharing this knowledge with your friends by using our sharing shortcuts. You can also leave any additional tips or questions in our comments section below. Thank you.