How to scp a folder from remote to local?
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?
scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/
从man scp
-r Recursively copy entire directories
To use full power of scp you need to go through next steps:
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
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:
-r
Recursively copy all directories and files /
, Get full location by pwd
scp
will replace all existing files hostname
will be hostname or IP address -P portnumber
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
链接地址: http://www.djcxy.com/p/4378.html上一篇: 为什么要使用Ruby的属性
下一篇: 如何scp文件夹从远程到本地?