On your server (A):
nc -l -p 1234 -q 1 > something.zip < /dev/nullOn your "sender client" (B):
cat something.zip | netcat server.ip.here 1234Answer from martinwguy on Stack Exchange
On receiving end:
nc -l 1234 > file.tar.gz
On sending end:
cat file.tar.gz | nc <reciever's ip or hostname> 1234
That should work. Depending on the speed, it may take a while but both processes will finish when the transfer is done.
From the nc(1) man page:
-lUsed to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options.
So your use of -p is wrong.
Use on server2:
nc -l 1234 > file.tar.gz
And on server1:
nc server2 1234 < file.tar.gz
Basically, a lot of times, I use tar and nc to transfer files over our local network. But when used in this way, the processes don't complete. The file is transmitted, but I have to Ctrl+C on either end to complete it.
On one end, I do tar -czf - ./directory | nc -l -p 3333 and on the other netcat host 3333 | tar -xzf -
Sometimes I put in a pv, to see the speed of transmission. When the file is transmitted, the pipes just hang there, on both ends, showing 0kB/s... But don't end.
I use Arch and the GNU Netcat (I think).
EDIT: Ok, here's what I found out. If I use the OpenBSD Netcat version, it works alright. But the GNU Netcat package doesn't work... So I guess this is a bug in the GNU Netcat? Where should I file it?
EDIT 2: It's NOT a bug. It's a FEATURE. On the GNU Netcat, you have to use the -c switch on the sending side. It makes Netcat close the connection after EOF. (Note: It doesn't matter who's the listener or who's the one that initiates the connection. The side that has the file and sends it needs to use the -c switch.)
And yet again, a mystery solved by myself.
If anyone is wondering why anyone in their right mind would do this, one valid reason is it allows for easy transferring of files with limited programs.
A lot of embedded Linux installations will have tar and nc but not scp or ftp.
This can help you get files off of a device with ease.
[ edit : I changed my phrasing to be non-exclusive ]
Just an idea. Try putting the listening netcat on the receiving side?