FTP 尝试从 dockerized Python 脚本连接时出现错误“500 Illegal PORT command”

FTP error "500 Illegal PORT command" while trying to connect from a dockerized Python script

我创建了一个 Python Flask 脚本,它可以在某些情况发生时将一些文件从 FTP 服务器移动到另一个服务器。 (FTP 服务器位于两个不同的 Docker 中) 在我的本地机器上,脚本工作正常,但是当我尝试将它放在 Docker 中时,它启动了,但是当请求到达时,我收到两个错误:

ftplib.error_perm: 500 Illegal PORT command.
ftplib.error_perm: 550 Illegal PORT command. Probably the file is no longer avaible on the FTP server?

由于我的本地机器运行良好,我认为这可能是 docker 的问题。

这是触发复制的代码:

for filename, n in n_request:
    print(self.color + "File name: " + filename + " Count: " + str(n) + RESET, flush=True)
    if n >= int(self.count):
        print(self.color + "Mooving file: " + filename + " from server: " + str(self.server) + RESET, flush=True)
        start = time.time()
        check = move_file(filename, self.server, self.client)
        end = time.time()

这是 move_file 函数:

def move_file(filename, server, client):
    from_ftp = FTP_handler(server[0], server[1], DEFAULT_USER, DEFAULT_PSW)
    to_ftp = FTP_handler(client[1], client[2], DEFAULT_USER, DEFAULT_PSW)
    return transfer_file(from_ftp, to_ftp, filename)

连接设置为被动模式。

如果您收到 "500 Illegal PORT command.",您使用的是主动模式,而不是被动模式。仔细检查并确保真正使用被动模式。

有关错误消息的解释(即使在不同的上下文中),请参阅:
.