首页 > 解决方案 > 无法使用 nc (netcat) 传输文件

问题描述

所以我有一个python脚本,它试图在两台机器之间通过nc传输一个大文件(1G)。这是为发件人启动进程的代码:

process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

在哪里

command =  nc -w 10 -4 *ip* *port* < file

这对于接收者:

    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

    command = nc -l -4 *port* > file

该文件传输损坏,并且比发送的文件小得多。

有趣的是,当我在接收端使用“-d”(从标准输入分离)标志时,它起作用了。但是现在我切换了机器,它的 nc 版本没有与 stdin 标志分离。此外,当我将 stdin = subprocess.PIPE 添加到 Popen 函数的参数时,它解决了以前机器上的问题,但没有解决这个问题。有什么建议么?

标签: pythonnetcat

解决方案


推荐阅读