scp
(Secure Copy Protocol)命令用于在本地和远程主机之间安全地复制文件或目录。它基于SSH协议,确保数据在传输过程中的安全性。
基本语法如下:
scp [options] [source] [destination]
-r
:递归复制整个目录。-P
:指定远程主机的端口(注意是大写的P)。-i
:指定用于身份验证的私钥文件。-v
:显示详细的操作过程,便于调试。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
-v
选项可以帮助您调试连接问题。-C
选项启用压缩,以提高传输速度。