nc

Linux nc command to send files

By creating a basic client/server model, you can use Netcat to transfer data from one host to another

2 min read
By myfreax
Linux nc command to send files
Linux nc command to send files

Netcat or nc is a command-line program that reads and writes data over a network connection using the TCP or UDP protocol. Considered the swiss army knife of networking tools.

Netcat is a cross-platform tool available for Linux, macOS, Windows and BSD. You can use Netcat to debug and monitor network connections, scan for open ports, transfer data, act as a proxy, and more.

Netcat packages are pre-installed on macOS and popular Linux distributions such as Ubuntu, Debian, CentOS, Fedora, etc.

nc command

The basic syntax form of the Netcat command is   nc [options] host port. host Can be the domain name of the remote host. Hostname or IP address.

port is the port, options is an option of the nc command, and is an optional parameter.

In Ubuntu, you can run the command netcat or nc. These are symbolic links to the OpenBSD version of Netcat .

By default, Netcat will attempt to establish a TCP connection to the specified host. If you want to establish a UDP connection, please specify -u options .

nc host port #tcp
nc -u host port #udp

Send File

By creating a basic client/server model, you can use Netcat to transfer data from one host to another.

First ask the computer on the receiving end, run the command nc -l 5555 > file_name, it will open port 5555 and receive data from the remote computer.

After the nc command receives the data, it will be written to the standard output , so we can write the data to the file through the redirection symbol > .

Finally, run the command nc receiving.host.com 5555 < file_name on the computer at the sending end to establish a TCP connection with the computer at the receiving end, < file_name which means using the file as the standard input of the nc command.

When the connection between the two computers is established, the nc command will start sending the file content to the host at the receiving end.

where the host at the receiving end can be an IP address or a host name, or an interpretable domain name.

nc -l 5555 > file_name #run on receivce of computer
nc receiving.host.com 5555 < file_name #run on send of computer

Conclusion

So far, you already know how to run the nc command in Linux to establish a TCP connection and send files. If you have any questions or comments, please leave a comment below.

Related Articles