linux服务器之间文件传输scp

linux scp 

Linux scp命令用于Linux之间复制文件和目录。

scp是 secure copy的缩写, scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令。

语法:

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user@]host1:]file1 [...] [[user@]host2:]file2

简单语法:

scp [参数] file1 file2

参数说明:

  • -1: 强制scp命令使用协议ssh1
  • -2: 强制scp命令使用协议ssh2
  • -4: 强制scp命令只使用IPv4寻址
  • -6: 强制scp命令只使用IPv6寻址
  • -B: 使用批处理模式(传输过程中不询问传输口令或短语)
  • -C: 允许压缩。(将-C标志传递给ssh,从而打开压缩功能)
  • -p:保留原文件的修改时间,访问时间和访问权限。
  • -q: 不显示传输进度条。
  • -r: 递归复制整个目录。
  • -v:详细方式显示输出。scp和ssh(1)会显示出整个过程的调试信息。这些信息用于调试连接,验证和配置问题。
  • -c cipher: 以cipher将数据传输进行加密,这个选项将直接传递给ssh。
  • -F ssh_config: 指定一个替代的ssh配置文件,此参数直接传递给ssh。
  • -i identity_file: 从指定文件中读取传输时使用的密钥文件,此参数直接传递给ssh。
  • -l limit: 限定用户所能使用的带宽,以Kbit/s为单位。
  • -o ssh_option: 如果习惯于使用ssh_config(5)中的参数传递方式,
  • -P port:注意是大写的P, port是指定数据传输用到的端口号
  • -S program: 指定加密传输时所使用的程序。此程序必须能够理解ssh(1)的选项。

实例:

1、从本地复制到远程

复制文件

scp local_file remote_user@remote_ip:remote_folder 
或者 
scp local_file remote_user@remote_ip:remote_file 
或者 
scp local_file remote_ip:remote_folder 
或者 
scp local_file remote_ip:remote_file 

案例:

#将本地superl1的test.txt文件传输到superl2服务器/home/superl2/test/文件夹下,需输入密码
scp /home/superl1/test/test.txt superl2@192.168.27.128:/home/superl2/test/ 

#将本地superl1的test.txt文件传输到superl2服务器/home/superl2/test/test2.txt(更换名称),需输入密码
scp /home/superl1/test/test.txt superl2@192.168.27.128:/home/superl2/test/test2.txt

#将本地superl1的test.txt文件传输到superl2服务器/home/superl2/test/文件夹下,需输入用户名、密码
scp /home/superl1/test/test.txt 192.168.27.128:/home/superl2/test/

#将本地superl1的test.txt文件传输到superl2服务器/home/superl2/test/文件夹下,需输入用户名、密码
scp /home/superl1/test/test.txt 192.168.27.128:/home/superl2/test/test2.txt 

复制文件夹

scp -r local_folder remote_user@remote_ip:remote_folder 
或者 
scp -r local_folder remote_ip:remote_folder 

案例:

#将本地的test文件夹复制到superl2服务器上/home/superl2/test/ ,需要输入用户密码
scp -r /home/superl1/test/ superl2@168.192.27.128:/home/superl2/test/ 


#将本地的test文件夹复制到superl2服务器上/home/superl2/test/ ,需要输入用户和密码
scp -r /home/superl1/test/ 168.192.27.128:/home/superl2/test/ 

2、从远程复制到本地

将file1和file2位置替换一下即可

#将superl2服务器上复制到/home/superl2/test/本地的test文件夹 ,需要输入用户密码
scp -r superl2@168.192.27.128:/home/superl2/test/ /home/superl1/test/  


#将superl2服务器上/home/superl2/test/复制到本地的test文件夹 ,需要输入用户和密码
scp -r 168.192.27.128:/home/superl2/test/  /home/superl1/test/ 

如果设定了防火墙,例如端口为1234

#scp 命令使用端口号 1234
scp -P 1234 -r superl2@192.168.27.128:/home/superl2/test/ /home/superl1/test/

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值