系统之间复制文件

我们现在系统之间复制文件,那么我们怎么做?
首先我们得有两个系统,比如client和server两个虚拟机。
他们之间能互联互通,网络是通的,比如我们首先得测试一下:
[root@localhost ~]# ping 192.168.92.129
PING 192.168.92.129 (192.168.92.129) 56(84) bytes of data.
64 bytes from 192.168.92.129: icmp_seq=1 ttl=64 time=0.628 ms
64 bytes from 192.168.92.129: icmp_seq=2 ttl=64 time=0.286 ms
64 bytes from 192.168.92.129: icmp_seq=3 ttl=64 time=0.339 ms
64 bytes from 192.168.92.129: icmp_seq=4 ttl=64 time=0.295 ms
64 bytes from 192.168.92.129: icmp_seq=5 ttl=64 time=0.300 ms
64 bytes from 192.168.92.129: icmp_seq=6 ttl=64 time=0.609 ms
64 bytes from 192.168.92.129: icmp_seq=7 ttl=64 time=1.13 ms
64 bytes from 192.168.92.129: icmp_seq=8 ttl=64 time=0.316 ms
64 bytes from 192.168.92.129: icmp_seq=9 ttl=64 time=0.242 ms
64 bytes from 192.168.92.129: icmp_seq=10 ttl=64 time=0.243 ms
64 bytes from 192.168.92.129: icmp_seq=11 ttl=64 time=0.287 ms
^C
— 192.168.92.129 ping statistics —
11 packets transmitted, 11 received, 0% packet loss, time 10003ms
rtt min/avg/max/mdev = 0.242/0.425/1.131/0.257 ms
[root@localhost ~]#

通过上面我们验证,两个系统之间是通的。

那么现在我们远程传送文件或远程复制文件。
[root@localhost home]# ls
lgb.tar lgb.tar.bz2 lgb.tar.gz lgb.tar.xz
[root@localhost home]# scp lgb.tar.gz root@192.168.92.129:/home
The authenticity of host ‘192.168.92.129 (192.168.92.129)’ can’t be established.
ECDSA key fingerprint is 0a:6c:2e:b7:7f:4b:22:96:13:67:92:7d🇩🇪b5:76:d3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.92.129’ (ECDSA) to the list of known hosts.
root@192.168.92.129’s password:
lgb.tar.gz 100% 157 0.2KB/s 00:00
[root@localhost home]#

远程系统server:

那么我们现在想利用sftp远程传送文件,它需要借助远程服务器的SSHD这个后台服务。
[root@localhost home]# ls
lgb.tar lgb.tar.bz2 lgb.tar.gz lgb.tar.xz
[root@localhost home]# sftp root@192.168.92.129
root@192.168.92.129’s password:
Connected to 192.168.92.129.
sftp>
sftp> ls
anaconda-ks.cfg
sftp> cd /home
sftp> ls
lgb lgb.tar.gz
sftp> put lgb.tar
Uploading lgb.tar to /home/lgb.tar
lgb.tar 100% 10KB 10.0KB/s 00:00
sftp> ls
lgb lgb.tar lgb.tar.gz
sftp>

我们也可以利用sftp远程读取文件
我们首先在远程服务器端server新建一个文件test2.txt

那么我们在client端读取远程文件test2.txt
[root@localhost home]#
[root@localhost home]# ls
lgb.tar lgb.tar.bz2 lgb.tar.gz lgb.tar.xz
[root@localhost home]# sftp root@192.168.92.129
root@192.168.92.129’s password:
Connected to 192.168.92.129.
sftp>
sftp> ls
anaconda-ks.cfg
sftp> cd /home
sftp> ls
lgb lgb.tar.gz
sftp> put lgb.tar
Uploading lgb.tar to /home/lgb.tar
lgb.tar 100% 10KB 10.0KB/s 00:00
sftp> ls
lgb lgb.tar lgb.tar.gz
sftp>
sftp>
sftp> ls
lgb lgb.tar lgb.tar.gz test2.txt
sftp> get test2.txt
Fetching /home/test2.txt to test2.txt
/home/test2.txt 100% 12 0.0KB/s 00:00
sftp> exit
[root@localhost home]# ls
lgb.tar lgb.tar.bz2 lgb.tar.gz lgb.tar.xz test2.txt
[root@localhost home]#

Rsync它可以保证系统间安全同步文件
有三种功效:1、本地同步文件;2、远程同步文件;3、文件属性(权限,时间戳等等)

那么我们首先看一下
1、 本地不同文件;
[root@localhost /]# rsync -av /home /tmp
-bash: rsync: command not found
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost mnt]# yum install -y rsync
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
–> Running transaction check
—> Package rsync.x86_64 0:3.0.9-17.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size

Installing:
rsync x86_64 3.0.9-17.el7 local_repo 360 k

Transaction Summary

Install 1 Package

Total download size: 360 k
Installed size: 732 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : rsync-3.0.9-17.el7.x86_64 1/1
Verifying : rsync-3.0.9-17.el7.x86_64 1/1

Installed:
rsync.x86_64 0:3.0.9-17.el7

Complete!
[root@localhost mnt]#
rsync -av /home /tmp

[root@localhost /]# rsync -av /home /tmp
sending incremental file list
home/
home/lgb.tar
home/lgb.tar.bz2
home/lgb.tar.gz
home/lgb.tar.xz
home/test2.txt

sent 11100 bytes received 111 bytes 22422.00 bytes/sec
total size is 10766 speedup is 0.96
[root@localhost /]# cd /tmp
[root@localhost tmp]# ls
home yum.log yum_save_tx.2020-07-15.15-07.24xEJc.yumtx yum_save_tx.2020-07-15.15-07.Kmm0wz.yumtx yum_save_tx.2020-07-22.10-35.z4yIDt.yumtx yum_save_tx.2020-07-22.10-39.135ChR.yumtx
ks-script-yqiEfC yum_save_tx.2020-07-15.15-05.CVv0Ya.yumtx yum_save_tx.2020-07-15.15-07.jroYeX.yumtx yum_save_tx.2020-07-22.10-34.wVOX0G.yumtx yum_save_tx.2020-07-22.10-36.J1jjFA.yumtx
[root@localhost tmp]# cd home/
[root@localhost home]# ls
lgb.tar lgb.tar.bz2 lgb.tar.gz lgb.tar.xz test2.txt
[root@localhost home]# pwd
/tmp/home
[root@localhost home]#

2、 远程同步
rsync -av /home root@192.168.92.129: /tmp

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值