nc妙用互传文件和发送消息

一、使用nc传输文件(不使用ftp或scp传输文件)
比如将A服务器(10.0.0.10)上的kahn.txt传送到B服务器(10.0.0.20)
#接收端事先建立端口3721等待接收文件kahn.txt
1、(10.0.0.20) # nc -l -p 3721 > kahn.txt
#发送端建立到目标ip和端口的网络连接并发送文件kahn.txt
2、(10.0.0.10) # nc 10.0.0.20 3721 < kahn.txt


二、两台服务器使用nc进行文字聊天
#服务器端先建立端口
1、(10.0.0.20) # nc -v -l 3721
#客户端去连接服务器端的端口
2、(10.0.0.10) # nc -v 10.0.0.20 3721
#客户端开始发送消息
3、(10.0.0.10) # hello kahn123
#服务器端收到消息
4、(10.0.0.20) # hello kahn123
#注:当服务器端第一次收到消息后,双方就可以互相发送消息了。直到服务器端端口断开

猜你喜欢

转载自blog.csdn.net/xoofly/article/details/126852191