Skip to content Skip to sidebar Skip to footer

Ftplib Connectionrefusederror: [errno 111] Connection Refused (python 3.5)

I have a script that should connect to a FTP from ftplib import FTP with FTP('IP') as ftp: ftp.login(user='my user', passwd='my password') ftp.cwd('/MY_DIR') ftp.dir() I

Solution 1:

Solution

After using filezilla to debug the method, turn out that our FTP returned 0.0.0.0 despite we defined in /etc/vsftpd.conf

pasv_adress=IP

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

You have to comment

listen_ipv6=YES

and enable

listen=YES

in /etc/vsftpd.conf


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

to force the previous host if '0.0.0.0' is send


Post a Comment for "Ftplib Connectionrefusederror: [errno 111] Connection Refused (python 3.5)"