Linux – How to Send Files via Netcat

linuxnetcat

I'm using something like this to send file from one computer to another:

To serve file (on computer A):

cat something.zip | nc -l -p 1234

To receive file (on computer B):

netcat server.ip.here. 1234 > something.zip

My question is… can I do the opposite? Let's say I have file on computer B and I want to send it to A but not the way I wrote above, but by making computer that's supposed to receive file (A) be 'listening' server and connect computer that's 'sending' file (B) to server and send the file? Is it possible? I think it might be but I'm not sure how to do this.

In case my above explanation is messed up: How do I send file TO 'server' instead of serving the file on server and then taking it FROM it (like I did above)?

Best Answer

On your server (A):

nc -l -p 1234 -q 1 > something.zip < /dev/null
On your "sender client" (B):
cat something.zip | netcat server.ip.here 1234

Related Question