File transfer with Netcat

1295

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