How to download a file via SSH
This particular guide covers one specific feature – downloading files over SSH.
There are a few benefits SSH may offer in terms of downloading files:
- The connection is encrypted all the way through, so you may not worry about the fact that files may get compromised during the transfer
- With the help of SSH keys and aliases it’s possible to establish an SSH connection without entering the password each time, so it is possible to download private files in a secure way very quickly
- There are ample opportunities to make the whole process automatic. For instance, it’s possible to create a server-side script which would create a regular backup of your hosting account and another script on your computer which will allow downloading the fresh backup to your local computer on designated time.
Linux and OS X systems:
OpenSSH SSH/SecSH protocol suite (which comes pre-installed with OS X and available for download for most other *nix systems) includes the scp (secure copy) application which can be used to upload and download files from and to remote hosts.
Here are few examples of how to use it for:
1. Uploading a file from a local computer to a remote one:
scp /path/to/local/file username@hostname:/path/to/remote/file
This command can be used to upload a specific file to your account on the server:
scp -P 21098 /home/localuser/site/example.html cpanel_user@servername:/home/cpanel_user/public_html
Or this one, if the entire directory should be uploaded:
scp -P 21098 -r /home/localuser/site/ cpanel_user@servername:/home/cpanel_user/public_html
2. Downloading a file from a remote system to your computer:
scp username@hostname:/path/to/remote/file /path/to/local/file
This particular example can be used to download an error_log from public_html of a hosting account to your local computer:
scp -P 21098 cpanel_user@servername:/home/cpanel_user/public_html/error_log /home/localuser/logs/
NOTE: When one of the commands above is used, you will be asked to insert the password into your cPanel account (when you enter the password, it is automatically hidden for the security purposes)
Windows does not have native support for SSH, but there are a few workarounds.
1.You may use native Windows command line utilities included with Powershell command line shell.
To do that, select the Start button > click on the Run… option. In the command line type in powershell and press Enter:
Here is an example of the command for downloading the file from the server to your computer:
Invoke-WebRequest http://domain.com/path-to-file.zip -UseBasicParsing -OutFile local.zip
http://domain.com/path-to-file.zip should be replaced with the URL to the file in question
local.zip should be replaced with the name you would like the downloaded file to be stored with. You may also specify a full path there. By default, it will be downloaded to C:\Users\your-windows-username directory:
The Invoke-WebRequest uses the HTTP protocol instead of SSH one. Its sole resemblance to scp is that the command line interface is being used as well.
This method has its disadvantages. First of all, the connection is not encrypted unless you have an SSL certificate and a specified https:// protocol in your URL. The file should be publicly accessible, which is not acceptable in some cases. Also, the file contents are stored in memory before being recorded to the disk, making this approach unsuitable for downloading large files.
2.Another workaround includes installing the Cygwin command line interface for Windows, which features the scp command. In order to use it, do the following:
- Download the cygwin installation file from here
- Install cygwin on your computer (do not forget to include openssh from the net bundle during installation process)
- Once installed, you will be able to run the scp command from the first part of the article using the Windows command line terminal (accessible via the Start button > Run… option > In the command line, type in cmd and press Enter).
Need any help? Contact our HelpDesk