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…