File transfer with Netcat

Posted by: Andrea Benini

Tagged in: tcp , server , netcat , nc , Linux , file transfer

Andrea Benini

There's a basic usage for netcat helping you to transfer data/files across hosts without ssh or ftp services

Here's what I usually do on server (example IP: 1.2.3.4)

nc -l -p 6666 | uncompress -c | tar xvfp -

Basically I open TCP port 6666 (or whatever you want) on server and listen for raw compressed data

 

On my client I need to issue a command like this

tar cpf - /my/cool/dir | compress -c | nc -w 3 1.2.3.4 6666

Where /my/cool/dir is what I want to transfer, 1.2.3.4 is the destination host (server) and 6666 is the previously opened TCP port; you can even set a timeout (in seconds) for connection, suggested if you're in a busy network

 

Data on this stream are compressed so faster downloads are possible, this kind of trick is useful when you need to transfer data on the fly or when you don't have ssh shell host, scp or ftp server; I use it heavily expecially on embedded devices or dumb machines

 

Hope it helps

 

Andrea Ben Benini

Comments (1)Add Comment
Shawn Holland
Informative.. Thanks
written by Shawn Holland, June 18, 2009
This is prety sweet. I don't have a use for it ATM but I can definately see its usefulness. I'm adding this to my favorites.

Thanks for the informative post.

--
Shawn

Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.

busy