Skip to content

Instantly share code, notes, and snippets.

@minlaxz
Last active November 16, 2020 20:07
Show Gist options
  • Save minlaxz/2782a783ff853ebf042ccc48d81e56c6 to your computer and use it in GitHub Desktop.
Save minlaxz/2782a783ff853ebf042ccc48d81e56c6 to your computer and use it in GitHub Desktop.
Using Netcat for File Transfers. Netcat is like a swiss army knife for geeks.

$ pv TensorRT-7.2.1.6.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz | nc -w 3 172.17.0.2 6969 nc -l -p 6969 > TensorRT-7.2.1.6.Ubuntu-18.04.x86_64-gnu.cuda-11.0.cudnn8.0.tar.gz

On the receiving end running, nc -l -p 1234 > out.file
On the sending end running, nc -w 3 [destination] 1234 < out.file

For faster transfers if both sender and receiver has some basic *nix tools installed, you can compress the file during sending process,
On the receiving end, nc -l -p 1234 | tar x
On the sending end, tar cf - /some/dir | nc -w 3 [destination] 1234

A much cooler but less useful use of netcat is, it can transfer an image of the whole hard drive over the wire using a command called dd.
On the sender end run, dd if=/dev/hda3 | gzip -9 | nc -l 3333
On the receiver end, nc [destination] 3333 | pv -b > hdImage.img.gz

Be warned that file transfers using netcat are not encrypted, anyone on the network can grab what you are sending, so use this only on trusted networks.
Ref


Pull file FROM listener back TO Client
$ nc -l -p 5555 < giving_a_file.
$ nc -w 3 TargetIP Port > receving_a_file.
SANS Ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment