How To Copy A File Using Netcat

When you copy a file from one Linux server to another you’re first choice will be SSH. SSH is secure and ubiquitous and should be your first choice.

Sometimes the CPU overhead of SSH’s encryption can be the bottle neck on transfer speed. This handicap can be significant if you are copying huge amounts of data.

One way to avoid this is to use netcat.

Netcat allows you to move data between systems without using any encryption maximizing your transfer speed.

NOTE: This is totally insecure so you should think very carefully about where you use this technique.

First, on the destination server, start netcat listening on a port:

netcat -l -p <port> >OutFile

This command starts netcat listening (-l) on a port (-p <port>) and to direct the received data to a file (>OutFile).

Then, send the file from the source server with this command:

netcat <host> <port> <InFile

Set the <host> to the hostname or IP address of the receiving server and match the <port> with the listening port on the destional server.

The transfer will zip along as fast as either your network or storage device can move data.