Netcat/5/en

From aldeid
Jump to navigation Jump to search

File Transfer

Using pipes and redirection allows you to extend the functionality of Netcat, as shown by the following examples.

  • In a first terminal, enter:
$ nc –l –p 1234 > output.txt
  • In a second terminal (the input.txt file is supposed to exist in the root directory from which the command line is launched):
$ cat input.txt | nc 127.0.0.1 1234 –w 10

ou

$ nc 127.0.0.1 1234 -w 10 < input.txt

In the example above, the command issued in the first terminal can listen on port 1234 and redirect all that is given to the output.txt file. Control of the second terminal will display the file contents (cat input.txt), intercepted by netcat (using the pipe) which sends it to the host 127.0.0.1 on port 1234 Parameter -w 10 can automatically terminate the connection at the end of the operation (after a delay of 10 seconds).