跳到主要内容

SCP

Secure Copy Protocol 协议用于在系统之间安全的复制文件/文件夹。

语法

scp <source_file_name> <username>@<remote hostname or IP address>:<path>

scp [option] <username>@<source_host>:<path/to/source/file> <username>@<target_host>:<target/path>

用法

  • 将文件从本地主机复制到远程主机 (Local → Server)。
  • 将文件从远程主机复制到本地主机 (Server → Local)。
  • 在两个远程服务器之间复制文件 (Server → Server)。

文件权限

复制文件到远程服务器遇到异常,先用 ssh 登录试试,如果能登录,尝试修改文件夹权限 (如 sudo chmod 600 <path>)。

部分选项

-4, Forces scp to use IPv4 addresses only.
-6, Forces scp to use IPv6 addresses only.
-C, Compression enable.
-c cipher, Selects the cipher to use for encrypting the data transfers. This option is directly passed to ssh.
-i identity_file, Selects the file from which the identity (private key) for public key authentication is read.
-l limit, Limits the used bandwidth, specified in Kbit/s (限制带宽)
-p, Preserves modification times, access times, and file mode bits from the source file. (保留源文件中的修改时间、访问时间和文件模式位)
-P, port (指定端口)
-q, Quiet mode.
-r, Recursively copy entire directories.
-v, Verbose mode. Causes scp and ssh to print debugging messages about their progress. This is helpful in debugging connection, authentication, and configuration problems.

Resources