scp
是 secure copy 的缩写,用来在两台主机之间加密传送文件。它的底层是 SSH 协议,默认端口是22。
它主要用于以下三种复制操作。
使用scp
传输数据时,文件和密码都是加密的,不会泄漏敏感信息。
scp
的语法类似cp
的语法。
注意,如果传输的文件在本机和远程系统,有相同的名称和位置,scp
会在没有警告的情况下覆盖文件。
(1)本地文件复制到远程系统
复制本机文件到远程系统的基本语法如下。
# 语法
$ scp SourceFile [email protected]:directory/TargetFile
# 示例
$ scp file.txt [email protected]:/remote/directory
下面是复制整个目录。
# 将本机的 documents 目录拷贝到远程主机,
# 会在远程主机创建 documents 目录
$ scp -r documents [email protected]_ip:/path_to_remote_directory
# 将本机整个目录拷贝到远程目录下
$ scp -r localmachine/path_to_the_directory [email protected]_ip:/path_to_remote_directory/
# 将本机目录下的所有内容拷贝到远程目录下
$ scp -r localmachine/path_to_the_directory/* [email protected]_ip:/path_to_remote_directory/
(2)远程文件复制到本地
从远程主机复制文件到本地的语法如下。
# 语法
$ scp [email protected]:directory/SourceFile TargetFile
# 示例
$ scp [email protected]:/remote/file.txt /local/directory
下面是复制整个目录的例子。
# 拷贝一个远程目录到本机目录下
$ scp -r [email protected]_ip:/path_to_remote_directory local-machine/path_to_the_directory/
# 拷贝远程目录下的所有内容,到本机目录下
$ scp -r [email protected]_ip:/path_to_remote_directory/* local-machine/path_to_the_directory/
$ scp -r [email protected]:directory/SourceFolder TargetFolder
(3)两个远程系统之间的复制
本机发出指令,从远程主机 A 拷贝到远程主机 B 的语法如下。
# 语法
$ scp [email protected]:directory/SourceFile [email protected]:directory/SourceFile
# 示例
$ scp [email protected]:/files/file.txt [email protected]:/files
系统将提示您输入两个远程帐户的密码。数据将直接从一个远程主机传输到另一个远程主机。
-P
用来指定远程主机的 SSH 端口。如果远程主机使用非默认端口22,可以在命令中指定。
$ scp -P 2222 [email protected]:directory/SourceFile TargetFile
-p
参数用来保留修改时间(modification time)、访问时间(access time)、文件状态(mode)等原始文件的信息。
$ scp -C -p ~/test.txt [email protected]:/some/path/test.txt
-l
参数用来限制传输数据的带宽速率,单位是 Kbit/sec。对于多人分享的带宽,这个参数可以留出一部分带宽供其他人使用。
$ scp -l 80 [email protected]:/home/yourusername/* .
上面代码中,scp
命令占用的带宽限制为每秒80K比特位,即每秒10K字节。
-c
参数用来指定加密算法。
$ scp -c blowfish some_file [email protected]:~
上面代码指定加密算法为blowfish
。
-C
表示是否在传输时压缩文件。
$ scp -c blowfish -C local_file [email protected]:~
-q
参数用来关闭显示拷贝的进度条。
$ scp -q Label.pdf [email protected]:.
-F
参数用来指定 ssh_config 文件。
$ scp -F /home/pungki/proxy_ssh_config Label.pdf
-v
参数用来显示详细的输出。
$ scp -v ~/test.txt [email protected]:/root/help2356.txt
-i
参数用来指定密钥。
$ scp -vCq -i private_key.pem ~/test.txt [email protected]:/some/path/test.txt
-r
参数表示是否以递归方式复制目录。
使用 for 循环使用 JavaScript 显示 HTML 元素
结合 promise.then 和 async 函数的打印序列 JavaScript 测验