748

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,832
  • 10
  • 62
  • 88
NiLL
  • 13,645
  • 14
  • 46
  • 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 [email protected]: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

1165

In your terminal, type:

scp [email protected]: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 [email protected]:/remote/dir/foobar.txt /local/dir

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

Marek Grzenkowicz
  • 17,024
  • 9
  • 81
  • 111
Josh1billion
  • 14,837
  • 8
  • 38
  • 48
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
  • 12,484
  • 4
  • 54
  • 84
raj_gt1
  • 4,653
  • 2
  • 20
  • 28
  • 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
  • 204,365
  • 48
  • 270
  • 300
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
  • 26,473
  • 4
  • 65
  • 84
  • 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