且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ftplib ConnectionRefusedError:[Errno 111]连接被拒绝(python 3.5)

更新时间:2022-03-07 08:48:15

解决方案

使用filezilla调试方法后,发现尽管我们在/etc/vsftpd.conf

pasv_adress=IP

此帖子对我们有帮助: https://www.centos.org/forums/viewtopic.php?t = 52408

this post helped us : https://www.centos.org/forums/viewtopic.php?t=52408

您必须发表评论

listen_ipv6=YES

并启用

listen=YES

/etc/vsftpd.conf

如果您无法访问FTP的vsftpd.conf,也可以覆盖ftplib的FTP类.

Also you can override the ftplib's class FTP if you can't access to vsftpd.conf of the FTP

class CustomFTP(ftplib.FTP):

    def makepasv(self):
        if self.af == socket.AF_INET:
            host, port = ftplib.parse227(self.sendcmd('PASV'))
        else:
            host, port = ftplib.parse229(self.sendcmd('EPSV'), self.sock.getpeername())

        if '0.0.0.0' == host:
            """ this ip will be unroutable, we copy Filezilla and return the host instead """
            host = self.host
        return host, port

如果发送'0.0.0.0',则强制上一个主机

to force the previous host if '0.0.0.0' is send