Geeks Lunch - Intensive Version -HowTo's





NetCat

What's the fastest way to send files between computers?
netcat otherwise know as "nc". Faster than scp, or nfs,
easier to setup than ftp. You can even send a whole
filesystem across the net with it. Here's the
quick and dirty on netcat.


The Basics

Lets send a large ISO image from one Linux box to another as quickly as possible.
(They are typically large files)

on the sending machine type

cat big.iso | nc 192.168.1.2 81

(of course replace 192.168.1.2 with the receivers IP address)

on the receiver
nc -lp 81 > big.iso

That means "listen" on port 81 and put the results is file "big.iso"

You can verify the files are the same using md5sum

#md5sum big.iso
0bf4e1adb3e2312323e217a019328a40 big.iso


#md5sum big.iso
0bf4e1adb3e2312323e217a019328a40 big.iso

They match. Successful transfer.

On the receiver side you may need to disable the firewall.

/etc/rc.d/init.d/iptables stop

or for Fedora Core add something like
-A RH-Lokkit-0-50-INPUT -p tcp -m tcp --dport 22 --syn -j ACCEPT
to /etc/sysconfig/iptables

then
/etc/rc.d/init.d/iptables restart

So what if you want to send a whole directory tree?

Easy just add "tar"

on the sender side
tar -c directory_tree  | nc 192.168.1.2 81

On the receive side
nc -lp 81 | tar -x


Maybe you want to send an entire
partition?

On the sending side use

cat /dev/hda1 | nc 192.168.1.2 81

on the receive side

nc -lp 81 > hda2

Then to mount that filesystem on the receiver machine

mount ./hda2 /mnt -t ext3 -o loop=/dev/loop1

You can send the entire hard drive this way as well. Just be sure to have lots of disk space on the receiver side and time for slow network connections


Windblows?

Assume someone in a remote office has a badly broken windows box, or even a bad HD and you want to attempt to recover as much as of it as possible.

Have them send the windows partition across the net, work on it on your computer then send it back.  To do it boot a Knoppix cd and follow the instructions above.


Final thoughts

Netcat "nc" is included in most Linux distributions.  There is a version for windows and even win_ce.  If the files you are sending are text (or otherwise might respond well to compression) add "gzip" to transmit and receive streams. 







The most recent copy of this document is here.


http://www.geekslunch.com/gliv/netcat.html
written by: Monta Elkins


Back to GLIVH's [Geeks Lunch Intensive HowTo's]

email Monta @ [this domain]
Please send you comments/feedback/suggestions