- Download a file over an active SSH session
- How to Download Files from Remote Linux Servers
- Prerequisites
- Basic Syntax of Using SSH with SCP Command
- Create Files in Remote Linux Using SSH
- Download Remote Files Using SCP Command in Linux
- Download Remote Files with Port Number Using SCP Command in Linux
- Download Remote Files with Private Key Using SCP Command in Linux
- How to download a file from server using SSH? [closed]
- 4 Answers 4
- How to download a file through an SSH server?
- 7 Answers 7
Download a file over an active SSH session
I want to download a file from an active SSH session. In many cases I probably could just use SFTP, scp , rsync et al but there are times where I have elevated permissions on the remote server in a way I cannot use these methods. If you’re struggling to understand what I mean, imagine that you wanted to download something from /root/ or /var/log/auth.log . Root login is disabled (because we’re not idiots). How do you get that file? Copy it out somewhere less protected and then move it? This is clunky. There are also scenarios where the remote path is complex or temporary, or isn’t even a path because I want the output of a remote command stored locally. Store remotely, then copy? Clunk! There are several more clunky ways to achieve versions of these but in an ideal world, I would have something akin to local write access from the remote server, using the existing SSH session as a conduit. Something like (this is just an artist’s impression):
$oli@remote: cp /root/cheesecake /local/
And it just appears in my local cwd . And bidirectional access wouldn’t be a bad thing. It’s been eight long years since I asked this question and we’ve seen a real range of clunk, but it remains a problem that I still struggle with occasionally. I’ve refactored the question into something a lot more idealistic. I fully understand that there may not currently be a perfect answer. All past and future efforts towards my ideal are appreciated.
Interesting question! It really shows how peoples’ ideas of what is sensible to do get shaped by the tools they use. zssh is probably closest to the zmodem-like workflow you may be remembering.
And the sadder part for me is, these answers are unlikely to work when chaining connections like I have to at work.
At least for small files this should be possible with OSC8 & data URIs e.g.: file=»/var/log/auth.log»; content=»$(base64 $file)»; printf ‘\e]8;;data:file/plain;base64,’$content’\e\\’$file’\e]8;;\e\\\n’ (configure your os to use chrome to handle «data:» URIs; you will loose the filename here but with a nested approach it should also be possible )
How to Download Files from Remote Linux Servers
The mechanism of a computer user accessing different directory files on different hard disk partitions is comparatively similar to how SSH is used to access remote machines existing under a common or different network.
This network can be public like the Internet or private like LAN (Local Area Network) and SSH makes it possible for these machines to be accessible but what about downloading their associated files?
Prerequisites
This article is for the Linux user on a desktop environment who wishes to access and download files on a remote Linux server environment via SSH.
You need to have authenticated access to these two Linux environments and some familiarity with the Linux command-line interface.
Basic Syntax of Using SSH with SCP Command
The SSH (Secure Shell) protocol is used to enable the SCP (Secure Copy) command to successfully accomplish specific file download objectives from a Linux server environment to a Linux desktop environment.
The standard syntax of using the SSH command with the SCP command looks like the following:
$ scp [email protected]_url_or_ip:/path/to/downloading/file/from/server /path/to/download/location/on/desktop
Firstly, you should know the username and the IP address or hostname of the remote server from where you wish to retrieve a specific file.
Secondly, you should accurately specify the relative path to your download file location on the remote server and the relative path to the download file storage location on your desktop computer.
Create Files in Remote Linux Using SSH
You can achieve successful file downloads from a remote Linux server environment to a Linux desktop environment through three techniques.
Before we reference the three SCP file download techniques, let us first have some files on our server that we wish to download. If these files already exist on your end, you are good to go. All you need is the files’ correct relative path.
Create files on a remote Linux server.
$ touch LinuxShellTips_secrets.pdf && ls $ touch LinuxShellTips_certification.pdf && ls $ touch LinuxShellTips_for_beginners.pdf && ls
Let’s check out three ways to download files from a remote Linux server.
Download Remote Files Using SCP Command in Linux
In reference to the above syntax rule, we can download our first file with the following approach from your desktop environment.
$ scp [email protected]:/home/ec2-user/LinuxShellTips_secrets.pdf /home/dnyce/Desktop/files
Check for the existence of the downloaded file:
$ cd /home/dnyce/Desktop/files && ls
Download Remote Files with Port Number Using SCP Command in Linux
Maybe you have defined a non-standard port or you want to use a standard port on your Linux server environment for handling all remote file downloads. In this case, you should adhere to the following syntax rule:
$ scp -P port_number [email protected]_url_or_ip:/path/to/download/file/on/server /path/to/download/location/on/desktop
Let us try to download the second file we created:
$ scp -P 22 [email protected]:/home/ec2-user/ LinuxShellTips_certification.pdf /home/dnyce/Desktop/files
From the look of things, the download was a success.
Download Remote Files with Private Key Using SCP Command in Linux
If the remote server you are using restricts you to a private key/certificate for your remote connections, worry not. You can still achieve remote file download with the following syntax.
$ scp -i private_key/certificate_file.pem [email protected]_url_or_ip:/path/to/download/file/on/server /path/to/download/location/on/desktop
Let us try to download the third file we created using this approach.
$ scp -i my_file_name.pem [email protected]:/home/ec2-user/ LinuxShellTips_for_beginners.pdf /home/dnyce/Desktop/files
Your terminal instance should be on the same path as this certificate file.
Finally, let us check for the existence of the three downloaded files:
$ cd /home/dnyce/Desktop/files && ls
By using a wild card (*) , you could download all these files at once since they have a common file extension.
$ scp ec2-user@3.138.138.239:/home/ec2-user/*.pdf /home/dnyce/Desktop/files
This tutorial has taught us how to use SCP (Secure Copy) through the SSH protocol to accomplish specific file downloads from a remote server. The covered approaches are flexible enough to meet your remote files download needs.
How to download a file from server using SSH? [closed]
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
I need to download a file from server to my desktop. (UBUNTU 10.04) I don’t have a web access to the server, just ssh. If it helps, my OS is Mac OS X and iTerm 2 as a terminal.
4 Answers 4
scp your_username@remotehost.edu:foobar.txt /local/dir
replacing the username, host, remote filename, and local directory as appropriate.
If you want to access EC2 (or other service that requires authenticating with a private key), use the -i option:
scp -i key_file.pem your_username@remotehost.edu:/remote/dir/foobar.txt /local/dir
I think that there is a missing / between your_username@remotehost.edu: and foobar.txt in the above example.
Useful info — I didn’t realize you run this from your local machine, and not from the place you want to download from. so as Horak was asking, ~/ will dump it in your user directory like /Users/admin/ — I was logged in ssh remotely and wondered why it wasnt working.
You can do this with the scp command. scp uses the SSH protocol to copy files across system by extending the syntax of cp .
Copy something from another system to this system:
scp username@hostname:/path/to/remote/file /path/to/local/file
Copy something from this system to some other system:
scp /path/to/local/file username@hostname:/path/to/remote/file
Copy something from some system to some other system:
scp username1@hostname1:/path/to/file username2@hostname2:/path/to/other/file
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
export SOCKS_SERVER=127.0.0.1:1080 wget http://server-C/whatever
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
ssh address-of-B 'wget -O - http://server-C/whatever' >> whatever
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.