大文件传输(转移)

2017-10-06  本文已影响0人  老夫刘某

有时候,为了迁移网站,比如有大量的图片文件要进行迁移,通常使用的是rsync,其实除了rsync,我们还可以用nc命令进行迁移,这个命令需要用yum安装:
yum install -y nc
nc不仅可以用来传输,还能简易聊天:
A主机

[root@disconf ~]# nc  -l  1234
ls
who are you?
wo shi ni gege 

B主机

[root@YXH-Dev-Web-124 ~]# nc  10.40.2.74  1234
ls
who are you?
wo shi ni gege 

现在要将b主机的文件或者目录传送到A主机上,先在A主机上执行:
[root@disconf ~]# nc -l 1234|tar zxf -
然后去B主机上执行要传送的文件或者目录,这里我要传送的是test.txt文件:
[root@YXH-Dev-Web-124 ~]# tar zcf - test.txt |nc 10.40.2.74 1234
这样就传送到B主机了,
这里我创建了一个目录:

[root@YXH-Dev-Web-124 ~]# mkdir test
[root@YXH-Dev-Web-124 ~]# mv test111 test/
[root@YXH-Dev-Web-124 ~]# ll
drwxr-xr-x  2 root root 4096 Oct  6 14:30 test
drwxr-xr-x. 4 root root 4096 Aug  9 18:24 tools
[root@YXH-Dev-Web-124 ~]# tar zcf  - test |nc 10.40.2.74 1234

然后A主机上查看:

[root@disconf ~]# nc  -l  1234|tar zxf -
[root@disconf ~]# ll
drwxr-xr-x   6 root   root     4096 Sep  7 18:31 tengine_install
drwxr-xr-x   2 root   root     4096 Oct  6 14:30 test
-rw-r--r--   1 root   root        0 Oct  6 14:23 test111
-rw-r--r--   1 root   root        0 Oct  6 14:23 test.txt

可以看到,创建的文件和目录都过来了,其中上面的1234是指定的端口

不仅如此 ,nc命令还可以进行端口扫描:

[root@disconf ~]# nc -v -z -w2 127.0.0.1 1-100
nc: connect to 127.0.0.1 port 1 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 2 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 3 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 4 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 5 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 6 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 7 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 8 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 9 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 10 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 11 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 12 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 13 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 14 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 15 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 16 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 17 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 18 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 19 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 20 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 21 (tcp) failed: Connection refused
Connection to 127.0.0.1 22 port [tcp/ssh] succeeded!
nc: connect to 127.0.0.1 port 23 (tcp) failed: Connection refused
nc: connect to 127.0.0.1 port 24 (tcp) failed: Connection refused
上一篇下一篇

猜你喜欢

热点阅读