6

Linux nc命令发送文件 | myfreax

 1 year ago
source link: https://www.myfreax.com/linux-nc-command-to-send-file/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Linux nc 命令发送文件

通过建立TCP连接,nc命令可以将数据从一台主机传输到另一台主机

Updated At 20 Feb 2023 2 min read
By myfreax
Linux nc 命令发送文件

Linux nc 命令发送文件

Netcat 或 nc 是一个命令行程序,它使用 TCP 或 UDP 协议通过网络连接读取和写入数据。被视为网络工具的瑞士军刀。

Netcat是跨平台工具,可用于 Linux,macOS,Windows 和 BSD。您可以使用 Netcat调试和监视网络连接,扫描打开的端口,传输数据,作为代理等等。

Netcat软件包已预安装在macOS和流行的Linux发行版,如Ubuntu,Debian,CentOS,Fedora等。

Netcat 命令的基本语法形式是  nc [options] host porthost 可以是远程主机的域名。主机名或者是IP地址。port 是端口, options 是 nc 命令的选项,可选参数。

在 Ubuntu,您可以终端运行命令 netcatnc 。它们都是 Netcat 的 OpenBSD 版本的符号链接

默认情况下,Netcat 将会尝试建立与指定主机的 TCP 连接。如果要建立 UDP 连接,请指定 nc 命令的 -u 选项。

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

通过创建基本的客户端/服务器模型,你可以使用 Netcat 将数据从一台主机传输到另一台主机。

首先请在接收端的计算机,运行命令 nc -l 5555 > file_name,它将打开端口5555并接收来自远程计算机的数据。

nc 命令接收到数据后会写入到标准输出,因此我们可以将数据通过重定向符号 > 写入到文件 file_name

最后在发送端的计算机运行命令 nc receiving.host.com 5555 < file_name建立与接收端计算机的 TCP 连接,< file_name 表示使用文件作为 nc 命令的标准输入

当两个计算机之间的连接建立后,nc 命令将会开始发送文件内容到接收端的主机,这里的接收端的主机可以IP地址或者主机名,也可以是可解释域名。

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

至此,你已经知道如何在 Linux 运行 nc 命令建立 TCP 连接并发送文件。如果您有任何疑问或意见,请在下面发表评论。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK