Sending file from One Linux machine to another machine

I had some files which need to be sent a file from one Linux machine to another. Till that time my usual approach would be to download the file to my local desktop from first Linux machine then again upload it to second machine.
But recently I came to know about “nc” command which open a raw TCP/IP socket from one machine. We can use this command to send data from one machine to another directly

Step 1:- Set receiving computer in listening mode.

nc –l 9999 > abc.tar

This command will open a client socket on the current machine(say Target Machine) on port 9999 and listen on it. Whenever some program sends data on this port, it will dump those data to abc.tar file.

Step 2:- Send file from the sender computer

tar -cvpz <file or folder>  | nc 9999

This command will open a TCP/IP connection to , tar the file and send the raw stream to target machine on port 9999

This is much simpler and quicker way to transfer any file from one machine to another machine. There are many ways to use nc command some of them are listed here.

Advertisements

3 responses to “Sending file from One Linux machine to another machine

  1. why not a traditional scp to transfer the files? most probably, your linux box has sshd running.

  2. scp is interesting. Its good to know this command. Thanks for sharing this knowledge.

  3. I know nc and I was looking for something that can pipe and stream the contents of a log file to another box, but I didn’t make up the link between them before I saw your post. Great tipp! thanks! 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s