Intro to netcat
A few common commands for netcat
Introducing Netcat
Netcat is a networking tool that does some common networking actions very well. It is a very powerful tool but in most cases it is not encrypted. Here are a few common uses for this tool.
Copy large files to a remote machine quickly
First you need to listen on the remote machine. Connect to the remote machine via ssh. Then run the following command:
nc -l -p 1337 | tar xfp -
This will leave the nc process listening to port 1337/TCP expecting the contents of a tarball.
On the local system you need to send the tarball to the remote machine on port 1337/TCP. To do this run the following command:
tar cfp - /path/to/directory | nc -w 3 remote.cse.ucdavis.edu 1337
This will tar/gzip up the directory /path/to/directory and send it to the remote machine named remote.cse.ucdavis.edu on port 1337/TCP.
Note: If you add the z option to the tar command the transfer can be significantly slower depending on the speed of the processors on either end. For larger transfers you should remove it.
To receive a file named newfile on the destination system start netcat with the following command:
nc -l -p 1337 >newfile
On the source system send a file named origfile to the destination system with the following command:
nc destination 1337 <origfile
Issue a ^C on the source system and your done. Be sure to check the file to be sure it is the same size as the original.