I am not sure whether it is possible to scp a folder from remote to local, but still I am left with no other options. I use ssh to log into my server and from there I would like to copy the folder foo to home/user/Desktop (my local). Is there any command so that I can do this?

share|improve this question

closed as off-topic by jww, Xiong Chiamiov, Pang, rene, Mark Rotteveel Nov 12 '16 at 8:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about general computing hardware and software are off-topic for Stack Overflow unless they directly involve tools used primarily for programming. You may be able to get help on Super User." – Pang, rene, Mark Rotteveel
If this question can be reworded to fit the rules in the help center, please edit the question.

71  
@3bdalla this question is definitely on topic for stack overflow which includes questions about "software tools commonly used by programmers". – Abhi Beckert Jul 7 '15 at 0:09
20  
The OP's question was whether it is possible to copy file from remote to local host while ssh'd to remote host. I'm not sure why no single answer has correctly addressed his/her question. – JeffDror Jul 20 '15 at 13:04
2  
There goes your 1k upvote. – kaiser Sep 29 '16 at 19:42
3  
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. Also see Where do I post questions about Dev Ops? – jww Nov 12 '16 at 6:07
22  
OMG, I cannot believe this is closed. I get so frustrated by this kind of thing. – Mario Olivio Flores Jan 16 at 16:01

11 Answers 11

up vote 2902 down vote accepted
scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/

From man scp

-r Recursively copy entire directories
share|improve this answer
913  
I google this every time. Related comic: xkcd.com/1168 – cptloop Nov 26 '13 at 12:25
18  
and so is this command issued on the local machine or the remote machine? – abbood Dec 6 '13 at 16:18
15  
@abbood on the local machine – Gryphius Dec 6 '13 at 16:27
2  
@john-k, many possible reasons (scp not enabled on server, public key not authorized, file permission problem, ...). check if standard ssh works with your key first. consult the existing questions on that topic on sof/serverfault and if that doesn't help, ask a new one on serverfault with debug output from ssh / scp. – Gryphius Apr 28 '14 at 3:30
5  
Two nice-to-knows I found: the -C flag adds compression and the -c flag lets you pass in other cipher types for better performance, like scp -c blowfish a@b:something . as seen in dimuthu's answer – Automatico Jun 26 '14 at 20:48

To use full power of scp you need to go through next steps:

  1. Public key authorisation
  2. Create ssh aliases

Then, for example if you'll have this ~/.ssh/config:

Host test
    User testuser
    HostName test-site.com
    Port 22022

Host prod
    User produser
    HostName production-site.com
    Port 22022

you'll save yourself from password entry and simplify scp syntax like this:

scp -r prod:/path/foo /home/user/Desktop   # copy to local
scp -r prod:/path/foo test:/tmp            # copy from remote prod to remote test

More over, you will be able to use remote path-completion:

scp test:/var/log/  # press tab twice
Display all 151 possibilities? (y or n)

Update:

For enabling remote bash-completion you need to have bash-shell on both <source> and <target> hosts, and properly working bash-completion. For more information see related questions:

How to enable autocompletion for remote paths when using scp?
SCP filename tab completion

share|improve this answer
6  
Did not know about the config file, this is awesome! – dmastylo Mar 1 '14 at 20:27
8  
Unrelated to the OP's question. – blong Mar 4 '14 at 15:14
13  
@b.long The question is "How to copy remote folder foo to local Desktop". My answer is "scp -r prod:/path/foo /home/user/Desktop". Hope you're able to see relations. – Alexander Yancharuk Mar 6 '14 at 3:30
2  
@Bernhard For me is was obvious because I'm using bash-shell. Thanks for pointing me on that! Answer updated. – Alexander Yancharuk Mar 6 '14 at 6:16
1  
@Alexander Yancharuk : Thanks for the answer, this is more detailed than just covering the syntax alone. – Gladiator Mar 10 '14 at 9:32

To copy all from Local Location to Remote Location (Upload)

scp -r /path/from/destination username@hostname:/path/to/destination

To copy all from Remote Location to Local Location (Download)

scp -r username@hostname:/path/from/destination /path/to/destination

Custom Port where xxxx is custom port number

 scp -r -P xxxx username@hostname:/path/from/destination /path/to/destination

Copy on current directory from Remote to Local

scp -r username@hostname:/path/from/file .

Help:

  1. -r Recursively copy all directories and files
  2. Always use full location from /, Get full location by pwd
  3. scp will replace all existing files
  4. hostname will be hostname or IP address
  5. if custom port is needed (besides port 22) use -P portnumber
  6. . (dot) - it means current working directory, So download/copy from server and paste here only.

Note: Sometimes the custom port will not work due to the port not being allowed in the firewall, so make sure that custom port is allowed in the firewall for incoming and outgoing connection

share|improve this answer
1  
It seems (at least in recent versions of Raspbian Jessie and Ubuntu) that scp uses -P (uppercase P) for port, while (oddly) ssh uses -p (lowercase). – Adam Plocher May 22 at 13:42
    
@AdamPlocher, You are correct but roughly i always use -p (small) :) – Shiv Singh May 23 at 7:52
    
-p is reserved for preserving "modification times, access times, and modes from the original file". So if you're using that for port, it's probably not working ;-) Unless you have a different version that used the lowercase p differently. – Adam Plocher May 23 at 18:53
    
its working fine with Centos 7.1 and debian [root@host2 ~]# ssh root@host.xxxx.com -p xxxx root@host.xxx.com's password: just tested now – Shiv Singh May 24 at 9:37
    
With ssh, yes. Not with scp (I assume). – Adam Plocher May 25 at 3:10

What I always use is:

scp -r username@IP:/path/to/server/source/folder/  .

. (dot) : it means current folder. so copy from server and paste here only.

IP : can be an IP address like 125.55.41.311 or it can be host like ns1.mysite.com.

share|improve this answer
6  
Thank you for pointing out that . refers to current directory! – ericmjl Jan 12 '15 at 21:52

Better to first compress catalog on remote server:

tar czfP backup.tar.gz /path/to/catalog

Secondly, download from remote:

scp user@your.server.example.com:/path/to/backup.tar.gz .

At the end, extract the files:

tar -xzvf backup.tar.gz
share|improve this answer
9  
"Better" is highly depends on the data you are transferring and the effort it is to ssh to the server to do zipping/unzipping. And: you can add compression to scp with the -C flag, like scp -C a@b:bigfile .. – Automatico Jun 26 '14 at 20:43
3  
This reminds me of the comment made by @cptloop ! :D xkcd.com/1168 – GoodSp33d Aug 13 '15 at 8:51

And if you have one hell of a files to download from the remote location and if you don't much care about security, try changing the scp default encryption (Triple-DES) to something like 'blowfish'.

This will reduce file copying time drastically.

scp -c blowfish -r user@your.server.example.com:/path/to/foo /home/user/Desktop/
share|improve this answer
2  
According to this blog post you get even better performance with arcfour in stead of blowfish, but it has security flaws. – Automatico Jun 26 '14 at 20:42

Go to Files on your unity toolbar

enter image description here

Press Ctrl + l and write here_goes_your_user_name@192.168.10.123

The 192.168.1.103 is the host that you want to connect.

The here one example

enter image description here

share|improve this answer
    
Worked for me... Thanks! – ViniciusPires Mar 30 '16 at 20:07

Typical scenario,

scp -r -P port username@ip:/path-to-folder  .

explained with an sample,

scp -r -P 27000 abc@10.70.12.12:/tmp/hotel_dump .

where,

port = 27000
username = "abc" , remote server username
path-to-folder = tmp/hotel_dump
. = current local directory
share|improve this answer

In case you run into "Too many authentication failures", specify the exact SSH key you have added to your severs ssh server:

scp -r -i /path/to/local/key user@remote.tld:/path/to/folder /your/local/target/dir
share|improve this answer

The question was how to copy a folder from remote to local with scp command.

$ scp -r userRemote@remoteIp:/path/remoteDir /path/localDir

But here is the better way for do it with sftp - SSH File Transfer Protocol (also Secure File Transfer Protocol, or SFTP) is a network protocol that provides file access, file transfer, and file management over any reliable data stream.(wikipedia).

$ sftp user_remote@remote_ip

sftp> cd /path/to/remoteDir

sftp> get -r remoteDir

Fetching /path/to/remoteDir to localDir 100% 398 0.4KB/s 00:00

For help about sftp command just type help or ?.

share|improve this answer

I dont know why but I was had to use local folder before source server directive . to make it work

scp -r . root@888.888.888.888:/usr/share/nginx/www/example.org
share|improve this answer
    
Assuming the user had permissions, could you do an absolute path without using root@ – Jonathan Leaders yesterday

protected by Community Mar 6 '14 at 21:23

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.