Nectcat结束连接

时间:2014-11-16 11:38:20

标签: bash shell connection netcat

我使用netcat将文件发送到另一台PC,使用客户端和服务器。 问题是当我从服务器向客户端发送文件时,文件的内容被发送,但程序在两台计算机上都没有继续。

来自服务器的代码:

($nc -nlv $server < xa.txt) 

来自客户的代码:

($nc $ip_server $door > xa1.txt)
echo "done"

在这种情况下,不显示回声,并在控制台中接收文件,使连接和方块为全彩。

2 个答案:

答案 0 :(得分:0)

这是正常的:netcat读取到一端输入结束,并写入直到连接结束。它是这样设计的。

如果您要传输多个文件,请使用适用于此的协议:sftpscprsync

另一种方法是使用tarnetcat。在接收端做:

$ nc -lv $port | tar xvfz -

并在发送端执行:

$ tar cfz - * | nc $host $port 

答案 1 :(得分:0)

使用超时选项,例如

-q seconds   after EOF is detected, wait the specified number of seconds and then quit.

-w secs      timeout for connects and final net reads

嗯,我认为你不需要-w。

然而,ncat(insecure.org,这些创建了nmap的人)在看到EOF后立即断开连接。