How to send a file using netcat and then keep the connection alive?

孤街醉人 提交于 2019-12-03 13:50:31

Perhaps you were doing:

cat MY_FILE - | ncat ...

(Note that I've intentionally mispelled netcat, because I believe ncat is a superior program.)

Server side:

nc -k -l 10000 < my_in_file

Client side:

echo "bye" | netcat 192.168.1.6 10000 > my_in_file -
Angelos Mouzakitis

To keep listening for other connections use -k on nc.

suppose you want to make connection to server , server write to file and print to stdout ?

Server:

nc -k -l $PORT | tee file ( or > file without print to stdout)

Client

nc $IP $PORT < file_to_send

You can use the -q -1 option of nc:

echo MY_FILE | nc -q -1 192.168.0.1 9000

This way it will also work if the command is run in background.

I realise this thread is very old but and the OP uses unix, for reference here is a windows equivalent to "cat FILE - | ncat HOST":

type FILE con | ncat HOST

Then type CTRL-Z or CTRL-C to end the connection.

Notes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!