Transfer files via netcat and tar

netcat - smNetcat (nc) is a “…simple Unix utility which reads and writes data across network connections, using TCP or UDP protocol. It is designed to be a reliable back-end” tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities.” Basically it’s another small, cool Unix tool that allows you to do tons of cool stuff. I found this example out there that lets you transfer files via tar from one box to another. As with anything to do with nc, it’s dead simple, and logical. On the target box, start nc to listen on a port, and tar up anything it ‘hears’ like this:

nc -l -p $PORT | tar -xf -

Then, on the source system, have tar pipe out to netcat, that is pointed to the target host/ip:

tar -cf - $DIRECTORY | nc $HOST $PORT

Damn, how cool. There’s plenty more info out there, and the more you look the more you’ll realize what you can do with nc. Tons of great info at the above Wikipedia link, and I also found a great overview at Vulwatch.org. Have fun!

  • Jan

    I’m trying to do you example vi at (later with cron). But after the initial contact from the sending host, netcat on the receiving side exits!
    when I do the same on the command line it works.

  • Jan

    I’m trying to do you example vi at (later with cron). But after the initial contact from the sending host, netcat on the receiving side exits!
    when I do the same on the command line it works.

  • wch

    In the version of nc installed on my machine, the -p flag doesn’t work, and shouldn’t be there. It should just be “nc -l $PORT”.

  • wch

    In the version of nc installed on my machine, the -p flag doesn't work, and shouldn't be there. It should just be “nc -l $PORT”.

  • wch

    In the version of nc installed on my machine, the -p flag doesn't work, and shouldn't be there. It should just be “nc -l $PORT”.

  • msc

    If you add z flag for the both sides it will compress and decompress on the fly.
    Thank you for the tutorial

    • http://fak3r.com fak3r

      thanks, that should help the speed quite a bit

  • msc

    If you add z flag for the both sides it will compress and decompress on the fly.Thank you for the tutorial

  • http://fak3r.com fak3r

    thanks, that should help the speed quite a bit

  • http://fak3r.com fak3r

    thanks, that should help the speed quite a bit

Read previous post:
Andrew Bird – Heretics

Andrew Bird's new release, Armchair Apocrypha, doesn't come out until March 20th, but I'm already expecting it to be killer, [...]

Close