How to download file from ssh linux

How to Download a File from a Server with SSH / SCP

Users can securely download a file from any remote server with SSH by using the scp tool at the command line. Essentially this means you can have a file stored securely on a remote server and transfer it to local storage without having to expose that file to the outside world, because scp offers the same level of security and requires the same authentication that ssh does.

Securely downloading files with scp is aimed primarily at advanced users who are using ssh and the command line regularly in either macOS X, bsd, or linux. For those with adequate command line experience, using ssh and scp to download remote files is easy and, conveniently, after the file transfer has completed, the remote connection will end. This makes scp preferential to sftp for quick file downloads, though you could obviously use sftp if you wanted to as well.

Downloading a File from Remote Server with SSH Secure Copy

This assumes the remote server has ssh active, and if you’re able to ssh into the machine then it will have likely have scp active as well. If you don’t have a remote server to try this with, you can try it out between Mac OS X machines or with localhost if you enable ssh and Remote Login on the Mac beforehand.

The basic syntax to use scp (secure copy) for securely downloading remote files is as follows, replacing user, server, path, and target as appropriate:

scp user@server:/path/to/remotefile.zip /Local/Target/Destination

For example, to download a file to the local desktop named “filename.zip” located in the home directory of remote user “osxdaily” on server IP 192.168.0.45, the syntax would be as follows:

/Desktop/
Password:
filename.zip 100% 126 10.1KB/s 00:00
%

Assuming authentication is correct, the target file will immediately start to download to the target destination, offering a percentage completion, download speed, and elapsed transfer time as the file download proceeds.

As usual with the command line, it’s important to specify exact syntax.

If the file or path has a space in the name, you can use quotations or escaping on the path like so:

scp osxdaily@192.168.0.45:»/some remote directory/filename.zip»

scp can also be used to securely place a file on a remote server by adjusting the syntax as well, but we’re focusing on downloading a file rather than uploading files here.

If you’re new to ssh and testing this out yourself, and if you have never connected to the remote server before, you will be asked to confirm whether or not you wish to actually connect to the remote machine. This looks like so, and requires a ‘yes’ or ‘no’ answer before the download begins.
% scp osxdaily@192.168.0.4:filename.zip

/Desktop/
The authenticity of host ‘192.168.0.4 (192.168.0.4)’ can’t be established.
ECDSA key fingerprint is SHA256:31WalRuSLR83HALK83AKJSAkj972JJA878NJHAH3780.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.0.4’ (ECDSA) to the list of known hosts.
Password:
filename.zip 100% 126 0.1KB/s 00:00
%

Читайте также:  Сочетания клавиш windows значки

Again, assuming the connection is approve and the login is successful, the remote file will download from the target server to the localhost.

You can also use scp to download multiple files from a remote server:

Using ssh for remote file downloads like this is most appropriate for secure transfers which require authentication. Sure you can also downloading files with curl or wget from remote servers, but files accessible with curl and wget tend to be accessible from the outside world as well, whereas ssh and scp requires authentication or a key, and uses 3DES encryption, making it considerably more secure.

Источник

How to download a file through an SSH server?

I have a server in USA (Linux box B), and my home PC (Linux box A), and I need download a file from website C,

The issue is, it is very slow to download a file direct from A, so I need download the file when I log in B, and sftp get the file from A.

Is there any way that I can download file and use B as proxy directly through only one line command?

7 Answers 7

(Strange situation, doesn’t something like the triangle inequality hold for internet routing?)

Anyway, try the following, on A, ssh into B with a -D argument,

which acts as a SOCKS5 proxy on 127.0.0.1:1080 , which can be used by anything supporting SOCKS5 proxied connections. Apparently, wget can do this, by using the environment variable

Note that sometimes curl is more handy (i.e. I’m not sure if wget can do hostname lookups via SOCKS5; but this is not one of your concerns I suppose); also Firefox is able to work completely through such a SOCKS5 proxy.

Edit I’ve just now noticed that you’re looking for a one-line solution. Well, how about

i.e. redirection the wget -fetched output to stdout , and redirecting the local output (from ssh running wget remotely) to a file.

This seems to work, the wget output is just a little confusing («saved to —«), you can get rid of it by adding -q to the wget call.

Источник

How to Download a File From a Server to Your Desktop Using SSH

An SSH session is like a portal into 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 a file from SSH to your local desktop, such as if you are using one of our Linux VPS servers. And there’s no simple command from within 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’s made for precisely these kinds of situations.

Here’s how it works. First, we have a file on the remote server called filetodownload.txt , as shown here:

We’re going to transfer this file from Linux to our Windows desktop.

Table of Contents

Step 1: Gather the Necessary Information

To transfer a file from a remote server via SSH using SCP, we need the following pieces of information:

  1. Login credentials – username, server name or IP address, and password
  2. The port number for SSH connections
  3. The path to the file on the remote server
  4. The path to the download location
Читайте также:  C windows system32 rundll32 exe url

You should already have the login credentials when you connect to the server using PuTTY, or some other tool, so we won’t go into it here.

As for the port number, you’ll need to know which SSH server port your VPS listens to. It’ll either be 22 (the default port), or it’ll be given to you 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 on the CLI of the remote server while the file is in your current directory. This will give you the folder name, like this:

Now just append the name of the file 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:

Replace the sections in bold with the information you gathered in step 1. For example, the command used for this example is:

Step 3: Running the Command

Open up a command line 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 the yellow, and syntax highlighting is a nice change from the drab command line.

Pasting the above command into the local command line editor gives us:

As you can see, you first need to confirm the connection using the RSA fingerprint of the remote server. Once you type “yes”, it’ll be permanently added to the “known_hosts” file.

The “known_hosts” file in Windows is located at:

Replace [UserName] with your own Windows username. It’s a file without an extension, like this:

An editor like Notepad++ is ideal for these kinds of files. Each RSA fingerprint is added on a new line. This allows you to clear them easily by deleting an entire line at once if you ever need to remove an entry.

Once you provide your password in the prompt, the file is downloaded immediately, as shown here:

And you’re done! Navigate to the location you specified in your SCP command and the file should be visible.

SCP is the most direct way to transfer files from remote servers to local systems. It makes use of the same SSH protocols, so the connection is encrypted all the way through, making it immune to man-in-the-middle attacks. Hopefully, this tutorial will help you use it in an efficient, and easy manner. If you use one of our Managed Linux VPS services, and you have an issue with SCP or need more information about it please don’t hesitate 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, maybe consider sharing this knowledge with your friends by using our share shortcuts. You can also leave any additional tips or questions in our comment section below. Thank you.

Читайте также:  Аудиовыход через другое гнездо linux

Источник

How to download file from ssh linux

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).

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:

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:

You can use PowerShell on other Windows versions as well following the next workarounds:

To use native Windows command line utilities, 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).

Источник

Оцените статью