scp
(secure copy)是一个基于SSH的命令行工具,用于在本地和远程计算机之间安全地传输文件。以下是使用scp
命令进行文件传输的基本语法和一些示例:
scp [选项] [源文件/目录] [目标文件/目录]
-r
:递归复制目录及其内容。-P
:指定目标主机的端口号(默认是22)。-v
:详细模式,显示传输过程中的详细信息。-C
:启用压缩。-i
:指定私钥文件(用于身份验证)。scp /path/to/local/file username@remote_host:/path/to/remote/directory
scp username@remote_host:/path/to/remote/file /path/to/local/directory
scp -r /path/to/local/directory username@remote_host:/path/to/remote/directory
scp -P 2222 /path/to/local/file username@remote_host:/path/to/remote/directory
scp -C /path/to/local/file username@remote_host:/path/to/remote/directory
scp -i /path/to/private_key /path/to/local/file username@remote_host:/path/to/remote/directory
scp
命令时,确保目标主机的SSH服务是安全的,并且使用强密码或密钥进行身份验证。通过以上步骤,你可以使用scp
命令安全地在本地和远程计算机之间传输文件。