749

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.

Czechnology
  • 14,253
  • 9
  • 58
  • 83
NiLL
  • 12,907
  • 14
  • 41
  • 59
  • Try out this sftp : http://winscp.net/eng/download.php – Nishchit May 02 '15 at 11:21
  • 51
    why is this off topic? – jsmedmar Feb 24 '16 at 18:44
  • 4
    because it is not a programming question – Black May 02 '16 at 08:30
  • 26
    @EdwardBlack could have been migrated to unix.stackexchange instead – galdin May 31 '16 at 04:57
  • 3
    This worked for me `sudo scp -i ~/.ssh/id_rsa username@remotehost.io:Downloads/filename.sql ~/Desktop` – kaxi1993 Dec 05 '16 at 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](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Oct 09 '17 at 15:22

4 Answers4

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

Marek Grzenkowicz
  • 16,009
  • 8
  • 78
  • 100
Josh1billion
  • 14,554
  • 8
  • 33
  • 45
  • Is it possible to use with Amazon EC2? – NiLL Feb 24 '12 at 08:30
  • 3
    I'm not familiar with Amazon EC2, but if you have SSH access to your server, it should work. – Josh1billion Feb 24 '12 at 08:31
  • 3
    I think that there is a missing `/` between `your_username@remotehost.edu:` and `foobar.txt` in the above example. – Eugene S Feb 24 '12 at 08:47
  • 13
    @NiLL scp -i xxx.pem your_username@remotehost.edu:foobar.txt /some/local/directory – Helin Wang Oct 26 '12 at 04:37
  • If you need to copy file from server that is available through proxy, first use this recipe http://superuser.com/a/320438/219739 – Eugene Fidelin Jan 09 '14 at 10:15
  • how do I copy not only a file from a remote machine, but a directory? – アレックス Jan 29 '14 at 09:51
  • 3
    @Alex add the -r option. – SgtPooki Mar 26 '14 at 22:05
  • Silly question but how do I get the username? Can that just be root? – Karoh Mar 31 '14 at 18:27
  • @Horak: Yeah, root should work. – Josh1billion Mar 31 '14 at 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 Mar 31 '14 at 20:22
  • 10
    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 Jan 12 '16 at 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 May 02 '16 at 08:28
  • 3
    Add `-P port` option to connect to a specific port (half an hour to realize that it wasn't `-p` – tigerjack89 May 13 '16 at 05:39
  • what I am using windows? – FernandoZ Sep 06 '16 at 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 Sep 07 '16 at 15:51
  • how to download folder using scp command in ubuntu? – suresh pareek Mar 06 '17 at 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   
Sphinxxx
  • 10,302
  • 3
  • 43
  • 73
raj_gt1
  • 4,523
  • 1
  • 17
  • 27
  • 5
    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 Jul 10 '17 at 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 Sep 21 '17 at 18:06
  • 1
    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 Sep 21 '17 at 19:24
  • 2
    @MrPurple - Thanks for the warning, I almost did exactly that. I have edited the question to show the most relevant command first – Sphinxxx Jan 23 '18 at 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'
William Pursell
  • 174,418
  • 44
  • 247
  • 279
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.

J-16 SDiZ
  • 24,740
  • 3
  • 61
  • 82
  • 2
    Download from their web site, http://cyberduck.ch/Cyberduck-4.2.1.zip – J-16 SDiZ Feb 24 '12 at 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 Apr 21 '15 at 01:13
  • 12
    This does not answer the question. – edwinj Sep 15 '15 at 11:26
  • 1
    It does, it's easy enough to download using Cyberduck's SFTP – Miguel Stevens Jul 12 '17 at 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 Oct 22 '17 at 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 solution – mattLummus Apr 05 '18 at 14:57