How to send a file using netcat and then save the connection to the network?

I write out the command:

netcat serveraddress myport < MY_FILE 

The fact is that netcat sends a message to close the connection after sending the file. I need to write messages from the console after sending this file. I remember that I did something that could be used for stdin .. was it?

 netcat serveraddress myport < MY_FILE | 

This does not work now.

I am on unix.

Additional information: this did not imply server-side control (EG use netcat on the server to listen for an incoming connection)

+6
source share
5 answers

Perhaps you did:

 cat MY_FILE - | ncat ... 

(Note that I intentionally misused netcat because I believe ncat is an excellent program.)

+10
source

Server side:

 nc -k -l 10000 < my_in_file 

Client side:

 echo "bye" | netcat 192.168.1.6 10000 > my_in_file - 
+7
source

to listen to other connections, use -k on nc.

Suppose you want to connect to a server, write the server to a file, and print to stdout?

Server: nc -k -l $ PORT | tee (or> file without printing to standard output)

Client nc $ IP $ PORT <file_to_send

+6
source

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

 echo MY_FILE | nc -q -1 192.168.0.1 9000 

That way, it will also work if the command runs in the background.

+3
source

I understand that this branch is very old, but the OP uses unix, for reference it is the Windows equivalent of "cat FILE - | ncat HOST":

 type FILE con | ncat HOST 

Then enter CTRL-Z or CTRL-C to complete the connection.

Notes

+1
source

Source: https://habr.com/ru/post/924564/


All Articles