LAN file transfer using netcat

The following explanation is something I don’t want to miss from my blog because this helped me a lot in various situations. Actually this post was supposed to be here earlier than now. By the way, not boring you much, let me get into the topic.

All of you must have heard about ssh,sftp etc for remote login and file transfer between two machines in same LAN. Need to quickly transfer a file from one computer to another? No login is required if you are using netcat for the same. As a security concern netcat itself offers no way to control who can send what to whom. It’s syntax is as follows

nc [OPTIONS…] [hostname] [port]

For transfer to occur, both the machines must be connected in the same network. Suppose there are two machines, Host1 and Host2. To transfer a file from Host1 to Host2

On Host2, run
$nc -l 1234 > outputfile

On Host1, run
$nc <HOST2_IP> 1234 < inputfile

where 1234 is a random port number (preferably more than 1024), outfile is the file to be transfered and inputfile is the received file at Host2. Transfer can be done in the reverse direction if needed as follows

On Host2, run
$nc -l < inputfile

On Host1, run
$nc <HOST2_IP> 1234 > outputfile

Try these out…

Advertisements

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