chatting and transfer file with netcat
February 28th, 2007 mysurface Posted in Admin, nc | Hits: 33382 | 8 Comments »
netcat, or sometimes the command known as nc capable of doing a lots of thing. The examples of how to use nc to scan open ports showing here.
Here, using netcat to initiate a private chat, we need a listener server with open port and a client connect to the listener server.
Listener: (IP: 192.168.1.1)
nc -l 5678
-l is listen, -p is to specify port.
Client:
nc 192.168.1.1 5678
Okay, both side can start chatting.
The same way for file transfer. Let say listener server as a file receiver and client as a sender.
Listener: (Receiver)
nc -vv -l 5678 > dump.mp3
-vv is make the transaction very verbose, so that you will know what is happening.
Client: (Sender)
nc 192.168.1.1 5678 < dump.mp3
File transfer using nc usually fast, because it do not do encryption/decryption over the communication. It is good for transfer file from point to point or in LAN. You can do it over internet but you need to make sure you have do port forwarding on the listener port.







March 2nd, 2007 at 11:20 am
for the above examples to work on all systems it might be necessary to first do a ln -s /usr/bin/netcat /usr/bin/nc because afaik on systems like opensuse the binary is called netcat and not nc
July 28th, 2007 at 8:55 am
why would someone want to make a link, just replace netcat with nc and viseversa.
August 3rd, 2007 at 4:21 am
Why would you create a link OR replace the files.
Just create an alias!
July 23rd, 2008 at 2:54 pm
man page of nc says “It is an error to use -p option in conjunction with the -l option”. so in my case, the worked solution was:
cat filename | nc -l 3333 (on server, file sender)
nc 192.168.1.5 3333 > filename (on client, file receiver)
July 23rd, 2008 at 7:05 pm
@kamran, I think when I wrote this post, I am using the older version of nc, which that needs -l and -p. By the way, thanks for raising this up, let me amend my post.
July 24th, 2008 at 7:21 pm
thnx kamran that was helpful!
March 4th, 2009 at 10:34 pm
@mysurface, i think there is some conflict. different distributions giving different versions (or may be different falvors) of netcat. the solution i proposed in a previous comment worked for me in fedora 9, and fedora 10. but now i have switched to PCLinuxOS and this solution no longer works. so i tried your solution and it worked.
June 4th, 2011 at 10:51 am
Hello mate. I am still very new in blogging and all aspects around this industry. There are lods of terms I still don’t know. I’m not really sure I can write half decent to yours. I am gonna read the entire site perhaps I can grasp your blogging style a little.