Thursday, March 15, 2012

using NETCAT to transfer files

EXAMPLE 1

using hosts, RECEIVER and SENDER, NETCAT a file from one machine to another


a. set up the remote listener

receiver:~/INCOMING # nc6 -l -p 9876 > newname.tar

"-l" says LISTEN
"-p port" is the port to listen on


b. netcat the file from the sending machine

sender:~ # nc6 -x receiver 9876 < oldname.tar

"-x" makes it hang up after the transfer is done, ie. close down the receiver once the sender is done



c. use your file!

receiver:~/INCOMING # tar tf newname.tar | wc
27 27 307

ps. this will work with any arbitrary file, I used a .tar file simply to demonstrate that the file transferred properly in this example by running the sent file through tar itself to verify that it was good, it is probably prudent to verify that your file transferred properly - "cksum" and other similar utilities will help with that

sender:~ # cksum oldname.tar
3708157944 1505280 oldname.tar

receiver:~/INCOMING # cksum newname.tar
3708157944 1505280 newname.tar


EXAMPLE 2

using a receiver and a sender, TAR a directory from one machine to another



a. make a new directory for your incoming tar explosion

receiver:~ # mkdir INCOMING


b. set up the receiving end with a gtar

receiver:~/INCOMING # nc6 -l -p 9876 | gtar xvf -


c. send your tarred up directory

sender:~ # gtar cf - . | nc6 -x receiver 9876


the "-x" says transfer the file then hang up


d. now use your files!

receiver:~/INCOMING # nc6 -l -p 9876 | gtar xvf -
nc6: using stream socket
./
./.lesshst
./.vimrc
./nc6-1.0/
./nc6-1.0/CREDITS
./nc6-1.0/bootstrap
./nc6-1.0/aclocal.m4
./nc6-1.0/intl/
./nc6-1.0/intl/dcngettext.o
./nc6-1.0/intl/osdep.c
./nc6-1.0/intl/ngettext.c
./nc6-1.0/intl/gettext.o
....snip....
./.aliases
./.cvsrc
./.netrc
./.epltidyrc
./dot.tar




just from basic testing, this would seem to be about 20% faster than doing an "scp -c blowfish"

No comments:

Post a Comment