简介
scp
是 secure copy 的缩写,是基于ssh
的文件传输 命令/工具。
scp 是加密的,rcp 是不加密的,scp 是 rcp 的加强版。
Windows系统中,scp.exe就是scp,命令中输入scp.exe或scp都可以。
选项
选项 | 说明 |
---|---|
-r | 传输文件夹(递归复制整个目录) |
-P [port] | 指定SSH端口号 |
将远程电脑上的文件复制到本地
# 传输文件
scp remote_username@remote_ip:remote_file local_file
scp -P 22 remote_username@remote_ip:remote_file local_file
# 传输文件夹
scp -r remote_username@remote_ip:remote_path local_path
示例:复制远程电脑/var/www/html/目录下单favicon.ico文件,到d:盘;
示例目录/var/www/html/是安装了nginx才有的;
(1) 没有重命名,d:\的\加不加都可以
scp root@47.xx.xxx.90:/var/www/html/favicon.ico d:\
(2) favicon.ico重命名
为aaa.ico
scp root@47.xx.xxx.90:/var/www/html/favicon.ico d:\aaa.ico
将本地文件复制到远程电脑
# 传输文件
scp.exe local_file remote_username@remote_ip:remote_file
scp.exe -P 22 local_file remote_username@remote_ip:remote_file
# 传输文件夹
scp.exe -r local_path remote_username@remote_ip:remote_path
scp.exe -r -P 22 local_path remote_username@remote_ip:remote_path
示例:将d盘的bbb.ico图片,复制到远程电脑/var/www/html/目录下
scp d:\bbb.ico root@47.xx.xxx.90:/var/www/html/
Windows 10以下的系统需要自行下载openssh,再配置环境变量。