scp
网络
用法
scp [-P <port>] <src> <user>@<host>:<dest>通过 ssh 一次性复制文件;端口是大写 `-P`,远端路径要带冒号,而体量大或要反复传的场合 rsync 更合适,因为它会跳过没变的文件并能续传。
常用选项
| 选项 | 含义 |
|---|---|
| -P 2222 | Port, capital P. Lowercase -p means "preserve timestamps" here. |
| -r | Copy a directory and everything under it. |
| -i <key> | Use a specific private key. |
| -C | Compress in transit. |
| -3 | Copy between two remote hosts by routing through your machine. |
| -O | Use the old SCP protocol; OpenSSH 9 and later default to SFTP. |
示例
scp -P 2222 build.tar.gz deploy@example.com:/tmp/Upload one file. The remote side needs the colon.
scp -r deploy@example.com:/var/log ./logsDownload a whole directory.
连不上的时候,这些能把范围缩小——是名字解析不了、没有路由,还是端口被挡。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. scp 是做什么的?
通过 ssh 一次性复制文件;端口是大写 `-P`,远端路径要带冒号,而体量大或要反复传的场合 rsync 更合适,因为它会跳过没变的文件并能续传。
Q. 怎么写?
scp [-P <port>] <src> <user>@<host>:<dest> —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 6 个,完整列表在 man scp。这条命令属于网络。
相关命令
man 手册: man scp