Note, I have looked at Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? ), but it doesn't seem to apply to my case. I'm using the netcat (nc) that comes with busybox, and none of the workarounds I've found seem to work for me. Also, there is no -d
option, nor are there any -q
options.
I'm trying to use netcat to receive a file in a shell script, and this script is in a background process that apparently doesn't have a stdin. I have tried several different approaches, but none seem to work. Here's what I've tried:
nc -l -p 8888 > file
returns the instant the remote sender connects, dropping the connection early.nc -l -p 8888 < /dev/null > file
does the same.echo -n | nc -l -p 8888 > file
does the same.tail -f /dev/null | nc -l -p 8888 > file
will receive the file, but it doesn't quit when the file transfer is finished.
I'm running out of ideas. Is this version of netcat fundamentally broken?