Matteias Collet

Simple data transfer via netcat

Created at: / Last updated at:

Some simple commands to transfer text or files via netcat from one host to another using netcat over TCP (in plaintext).

Recipient

The recipient listens on a port for TCP traffic.

# -l                 Listen for incoming connections
# -p <listen port>   The port to listen on
nc -l -p <listen port>

Sender

The sender sends a message to the recipient via TCP and closing the connection once the message is completed.

# <recipient-ip>    The IP address of the recipient
# <recipient-port>  The port the recipient is listening on
# -q <seconds>      Optional, the number of seconds to wait before closing the connection after EOF.
#                   Should be > 0
nc <recipient address> <recipient port> -q <seconds>

Examples

Sending a simple input

# Recipient
nc -l -p 7777
 
# Sender
echo "Hello World" | nc -u 127.0.0.1 7777 -q 1

Sending a file

# Recipient
nc -l -p 7777 > out.file
 
# Sender
nc 127.0.0.1 7777 -q 1 < in.file