Transfering

Who’s cat?

Skip this part if you already know netcat… Netcat (nc) is the swiss army knife for networking (tcp/udp). From the name you can also deduce that it’s like the unix cat command, but then for network sockets instead of file sockets.
I’m using the ‘original‘ version created by hobbit in 1996. It has also been ported to windows (nc.exe).
In the mean time there is a more advanced edition written under the gnu license but I didn’t experiment with that one yet.
Netcat has two modes:

  • connect mode in which it connects to a certain host on a certain (tcp or udp) port, it outputs (and gets input) from the terminal
    Connect mode works like this:
    nc
    e.g. to connect to google port 80 you’d do
    nc http://www.google.com 80
    Very similar to telnet, except that it doesn’t interpret controlcodes like telnet does. But netcat also has a listen mode and this is what makes it alot better than telnet.
  • listen mode in which netcat waits for connections and links them to the terminal (stdout/stdin). To listen for a connection on port 20002:
    nc -l -p 20002
    To keep listening, even after the first connection use
    nc -L -p 20002

you can use -v, -vv or even -vvv to make it more verbose about the steps it takes to set up the connection.
“Very nice but what can I do with it in practice??”

Filetransfers with netcat

When there is no filtering between 2 hosts you can use netcat to quickly transfer a single file, directories (recursive or not) and even disk images.

  • Single file
    On the receiving host execute this

    nc -lp 20002 > /where/do/you/want/to/put/it.txt

    Then on the sending host

    nc receiving-host 20002 < /file/to/sent.txt

  • Directory structure, using tar (so doesn’t work out-of-the-box on M$ OS)
    On the receiving host execute this
    cd /place/to/receive/stuff

    nc -lp 20002 | tar -xzf –

    On the sending host
    cd /directory/to/send

    tar -czf – . | nc receving-host 20002

Tags:

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


%d bloggers like this: