shell - How do I copy a folder from remote to local using scp?

ID : 191

viewed : 184

Tags : shellsshcommand-linecopyscpshell

Top 5 Answer for shell - How do I copy a folder from remote to local using scp?

vote vote


scp -r /home/user/Desktop/ 

By not including the trailing '/' at the end of foo, you will copy the directory itself (including contents), rather than only the contents of the directory.

From man scp (See online manual)

-r Recursively copy entire directories

vote vote


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 have this ~/.ssh/config:

Host test     User testuser     HostName     Port 22022  Host prod     User produser     HostName     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) 


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

vote vote


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

scp -r /path/from/local username@hostname:/path/to/remote 

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

scp -r username@hostname:/path/from/remote /path/to/local 

Custom Port where xxxx is custom port number

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

Copy on current directory from Remote to Local

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


  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

vote vote


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 or it can be host like

vote vote


Better to first compress catalog on remote server:

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

Secondly, download from remote:

scp . 

At the end, extract the files:

tar -xzvf backup.tar.gz 

Top 3 video Explaining shell - How do I copy a folder from remote to local using scp?