Sunday, July 12, 2009

Fast Copy on Unix systems

I needed to copy so many small files and directories (1.2 TB) to another machine with netcat (nc). But I faced with a problem when I tried to run nc program on the background with bash. Bash was suspending standard input when I move nc process to background job, this was causing nc processess to die when standard input was blocked. So, I have found another netcat like utility called socat. Socat is not stop execution while it was working as background job on bash shell. I was able to utilize 100mbit ethernet with few socat processes on server and client side. First of all, I run socat processes on destination server as daemons to listen specific ports. Following, command will run socat in daemon mode to listen on tcp port 4123 and pipe incoming data to tar command on the background.

# (socat -u tcp4-listen:4123 - | tar xzp -C .) &

On source server, I run socat to feed incoming tar data to destination socat daemon where it listens on tcp port 4123. My destination server's ip adddess was .

# (tar -czp - /mydir/1/ | socat -u - tcp4:

So, with a simple bash script I was able to run few socat daemons on destination server with different ports and feed them from source server to achieve higher data transer rate.


xose said...

also try ncat:

xose said...

new ncat $HOME is: and included into nmap source code.

Amr_not_Amr said...

I cannot count how many times this posts saved me, and how much time and effort it has saved.
Really thanks a lot.

Amr_not_Amr said...

I cannot count how many times I've made use of this post. It has saved me too much time and effort.
Really thanks a lot :)