【问题标题】:FTP error "500 Illegal PORT command" while trying to connect from a dockerized Python script尝试从 dockerized Python 脚本连接时出现 FTP 错误“500 Illegal PORT command”
【发布时间】:2020-04-16 09:11:28
【问题描述】:

我创建了一个 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)

连接设置为被动模式。

【问题讨论】:

    标签: python docker flask ftp ftplib


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-11-25
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多