How do I actualy use netcat to transfer files over network? IIRC something like that nc -l -p 12345 > destfile(on the receiving end) + dd if=/dev/sourcedevice| nc ipaddress 12345(on the sending end) used to work. That is when the transfer was complete the sending process finished , terminated the tcp connection so the receiving process did quit as well. But now, the sending process just hangs (as if it could transfer anything after EOF) so the receiving process hangs as well. This is totally non scriptable.

I also tried -c on the sending end but that couses the destfile to be of random size (almost the expected size). Or maybe there is some reliable alternative to netcat?

  • Which /dev-device are you using? Could you please add a real example of what is not working?
    – Patrick B.
    Commented Feb 10, 2013 at 19:51
  • I want to transfer part of /dev/mapper/mainvg-rootlv. But it really makes no difference as the point is that netcat does not react to EOF (no matter if it is a real file, part of a file, or Ctrl-D from keyboard). Commented Feb 12, 2013 at 10:29

1 Answer 1


What I always do is:

nc -l -p 12345 > destfile
nc ipaddress 12345 < sourcefile
  • This might be ok, if you have the file on filesystem. But it won't do if you want to transfer only part of the file, by giving additional options to dd. Commented Feb 10, 2013 at 17:23
  • so you expect nc to get an EOF while you are only sending part of the file? Commented Feb 10, 2013 at 17:37
  • I mean EOF as end of input. In case of dd if=/dev/sourcedevice bs=1M count=1 the EOF should happen after 1MiB. Commented Feb 10, 2013 at 19:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .