I am issuing the command:
netcat serveraddress myport < MY_FILE
The thing is, that netcat sends a message to close the connection once the file is sent. I need to write messages from the console after sending that file. I remember to have done something to pipileline to stdin.. was it this?
netcat serveraddress myport < MY_FILE |
That isn't working now.
I'm on unix.
Extra info: This did not assume control on server side (E.G. use netcat on serverside to listen for the inbound connection)
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 -
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
- 'con' means console input, see http://ss64.com/nt/type.html
- It works with binary files.