Using netcat and tar to quickly transfer files between machines, aka tar pipe

So you have gigs of data to transfer between two machines over ethernet. A nice quick and dirty method is to use netcat and tar. This is by no means secure, but if you haven't got the time or desire to setup NFS, FTPd, Samba. Or wait hours for scp to do it's job then this can save you a lot of time.

Linux System using tar and netcat

On the receiving end do:

 # netcat -l -p 7000 | tar x

And on the sending end do:

# tar cf - * | netcat otherhost 7000


Depending on your hardware you might want to use compression with tar. You'll probably find your hard disk drive is a bottleneck on a fast network. Compression is useless if you can't saturate your network and will probably just slow things down. tar cf - * is copy everything in the current working directory. And your files will be untared at the other end from where you started the listening netcat. It won't be obivous that the operation is finished so you'll need to check network activity or top. This is indeed quick and dirty.

OpenBSD using tar and nc

OpenBSD usually offers a much tighter system rather than the mess you have with Linux. OpenBSD has it's own verison of netcat just refered as nc. The tar command is less sloppy than what you find in Linux. So if you're using two OpenBSD machines then one would do the following.

On the receiving end do:

 # nc -l 7000 | tar -xpf -

And on the sending end do:

 # tar -cf - * | nc otherhost 7000 
netcat.txt · Last modified: 2009/05/25 00:35 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready