We are able to connect to a server which is using explicit FTPS using curl with the following command:
> curl --ssl --list-only --user USER:PASSWD ftp://ftp.COMPANY.com:port/public
Yet this code hangs for a bit after logging "prot_p complete", and then returns "Connection timed out".
import ftplib
with ftplib.FTP_TLS() as ftps:
print('Connecting')
ftps.connect(URL, PORT)
print('Connected')
print('Logging in')
ftps.login(LOGIN, PASSWD)
print('Logged in')
ftps.prot_p()
print('prot_p complete')
ftps.retrlines('LIST')
After doing some research, it appears that ftplib does not play well with Microsoft's FTP server when using FTPS. To get it to work properly, you need to trick ftplib by forcing it to use EPSV mode. This can be done by setting the address family of the client to IPV6: