How to download a file from server using SSH?

Go To StackoverFlow.com

750

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.

2012-02-24 08:25
by NiLL
Try out this sftp : http://winscp.net/eng/download.ph - Nishchit Dhanani 2015-05-02 11:21
why is this off topic - jsmedmar 2016-02-24 18:44
because it is not a programming questio - Black 2016-05-02 08:30
@EdwardBlack could have been migrated to unix.stackexchange instea - gldraphael 2016-05-31 04:57
This worked for me sudo scp -i ~/.ssh/id_rsa username@remotehost.io:Downloads/filename.sql ~/Desktopkaxi1993 2016-12-05 14:23
Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See What topics can I ask about here in the Help Center. Perhaps Super User or Unix & Linux Stack Exchange would be a better place to ask - jww 2017-10-09 15:22


1166

In your terminal, type:

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

From: http://www.hypexr.org/linux_scp_help.php

2012-02-24 08:28
by Josh1billion
Is it possible to use with Amazon EC2 - NiLL 2012-02-24 08:30
I'm not familiar with Amazon EC2, but if you have SSH access to your server, it should work - Josh1billion 2012-02-24 08:31
I think that there is a missing / between your_username@remotehost.edu: and foobar.txt in the above example - Eugene S 2012-02-24 08:47
@NiLL scp -i xxx.pem your_username@remotehost.edu:foobar.txt /some/local/director - Helin Wang 2012-10-26 04:37
If you need to copy file from server that is available through proxy, first use this recipe http://superuser.com/a/320438/21973 - Eugene Fidelin 2014-01-09 10:15
how do I copy not only a file from a remote machine, but a directory - アレックス 2014-01-29 09:51
@Alex add the -r option - SgtPooki 2014-03-26 22:05
Silly question but how do I get the username? Can that just be root - Karoh 2014-03-31 18:27
@Horak: Yeah, root should work - Josh1billion 2014-03-31 18:36
Thanks josh, ok another silly question, how should I format my path?

"~/Users/horak/"

I'm in a sensitive place, just don't want to much anything up : - Karoh 2014-03-31 20:22

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 - Kai Qing 2016-01-12 18:16
Does not work, i tried ´scp your_username@remotehost:foobar.txt C:\´ to save it on my C drive, but it did not worked - Black 2016-05-02 08:28
Add -P port option to connect to a specific port (half an hour to realize that it wasn't -ptigerjack89 2016-05-13 05:39
what I am using windows - FernandoZ 2016-09-06 20:22
@FernandoZ the easiest solution would be to download WinSCP and use that, but if you want to do it from the command-line in Windows, I recommend downloading Cmder. That should have scp (and several other Linux tools) built into it. Another alternative would be to download GnuWin32, which is another set of Linux tools for Windows - Josh1billion 2016-09-07 15:51
how to download folder using scp command in ubuntu - suresh pareek 2017-03-06 15:19


322

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   
2012-02-24 08:42
by raj_gt1
I like how if one wanted to achieve OPs question and didnt fully read your answer they might accidently and without thinking simply run your first command and possibly overwrite the remote file they are trying to download with the local file they may have touched earlier. oops - Mr Purple 2017-07-10 02:10
Why there are accesses for? Someone can do "rm -rf /" without thinking but that does not reduce the utility of rm command - raj_gt1 2017-09-21 18:06
Do you think that starting an answer to "how should I upgrade linux?" with the "rm -rf /" command would also be a good idea - Mr Purple 2017-09-21 19:24
@MrPurple - Thanks for the warning, I almost did exactly that. I have edited the question to show the most relevant command firs - Sphinxxx 2018-01-23 01:43


96

scp is certainly the way to go, but for completeness you can also do:

$ ssh host 'cat /path/on/remote' > /path/on/local

or

$ cat /path/on/local | ssh host 'cat > /path/on/remote'

Note, this is UUOC, but < /path/on/local ssh host 'cat > /path' could cause unnecessary confusion.

And to proxy between two hosts:

$ ssh host1 'cat /path/on/host1' | ssh host2 'cat > /path/on/host2'
2012-02-24 14:40
by William Pursell
http://winscp.net/eng/download.ph - Nishchit Dhanani 2015-05-02 11:22
Has anyone done a speed test on the different methods? I'd be curious to know which one's fastest. Use case: I have a huge file to download - starbeamrainbowlabs 2015-09-30 19:33
This actually works with .ssh/config, whereas scp doesn't seem to follow the ssh configuratio - NoName 2017-02-23 00:50


13

If the SSH server support SFTP subsystem (this is part of SSH, and unrelated to FTP), use sftp. If it don't, try scp.

CyberDuck support all of them.

2012-02-24 08:28
by J-16 SDiZ
Download from their web site, http://cyberduck.ch/Cyberduck-4.2.1.zi - J-16 SDiZ 2012-02-24 08:30
It looks like they have since changed the software to be free, but you can optionally donate any amount and that will get rid of a "donation prompt" from within the program - Mike 2015-04-21 01:13
This does not answer the question - edwinj 2015-09-15 11:26
It does, it's easy enough to download using Cyberduck's SFT - Notflip 2017-07-12 12:27
FileZilla works great for me, and is free and open source (and made by the same guys that makes Firefox). as does Cygwin - hanshenrik 2017-10-22 11:46
Not exactly sure how one would consider the SSH File Transfer Protocol an invalid answer for a question about SSH file transfers. Perfectly adequate solutio - mattLummus 2018-04-05 14:57
Ads