Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Which /dev-device are you using? Could you please add a real example of what is not working? – Patrick B. Feb 10 '13 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). – Tomasz Grobelny Feb 12 '13 at 10:29

What I always do is:

nc -l -p 12345 > destfile
nc ipaddress 12345 < sourcefile
share|improve this answer
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. – Tomasz Grobelny Feb 10 '13 at 17:23
so you expect nc to get an EOF while you are only sending part of the file? – Lucas Kauffman Feb 10 '13 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. – Tomasz Grobelny Feb 10 '13 at 19:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.