使用 scp 做服务器间的文件传输

Jackey Linux 534 次浏览 , 没有评论

将本地文件复制到服务器:

scp localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

这里的localmachine/path_to_the_file是本地文件的路径,username@server_ip是服务器的用户名和ip,后面接的是服务器上的路径。运行命令,输入服务器的登录密码后,文件即被上传到了服务器/path_to_remote_directory的位置。

如果我们想复制整个文件夹中的内容到远程服务器呢?也非常简单,只需要加上一个参数-r,

scp -r localmachine/path_to_the_file username@server_ip:/path_to_remote_directory

从服务器复制文件到本地

如果是想获取服务器上的文件,只需要对上述命令稍加修改:

scp username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

同理,如果是获取服务器上的一个文件夹,也是加上参数-r:

scp -r username@server_ip:/path_to_remote_directory local_machine/path_to_the_file

复制服务器上的文件到另外一台服务器
假设我们没有登录服务器,想复制一台服务器中的文件到另外一台服务上面去:

scp username@server1_ip:/path_to_the_remote_file username@server2_ip:/path_to_destination_dire

 

参考链接:https://zhuanlan.zhihu.com/p/643429833?utm_id=0

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Go