Connecting to 'Explicit FTP over TLS' in Python (??)
*get* '227 Entering Passive Mode (10,19,1,137,195,128).\n'
The problem is that the server is returning the wrong IP address inside the response to the PASV command. This is typical for servers in some internal network behind some firewall. In this case 10.19.1.137 is returned, which is an IP address usable in local networks only.
This is a broken setup of the FTP server. But unfortunately such broken setup is common so many clients work around it by ignoring the given IP address in the response and using instead the IP address of the control connection. ftplib has no support for such workaround. But one can monkey patch it to provide such support:
from ftplib import FTP_TLS
# replace original makepasv function with one which always returns
# the peerhost of the control connections as peerhost for the data
# connection
_old_makepasv = FTP_TLS.makepasv
def _new_makepasv(self):
host,port = _old_makepasv(self)
host = self.sock.getpeername()[0]
return host,port
FTP_TLS.makepasv = _new_makepasv
ftp = FTP_TLS(ipAddress)
ftp.login(...)
ftp.nlst()
This is successfully tested with Python 2.7.12 and Python 3.5.2
When trying to download files using a Python FTP_TLS object getting AttributeError?
Your use of the timeout arg (which is an int) is in the PLACE of the context variable in this line:
FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, timeout)
Should be:
FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, context, timeout)
See:
https://docs.python.org/2/library/ftplib.html
Related Topics
Type Object 'Datetime.Datetime' Has No Attribute 'Datetime'
Converting "Yield From" Statement to Python 2.7 Code
Appending Item to Lists Within a List Comprehension
Python SQLite Parameter Substitution with Wildcards in Like
Scikit-Learn Dbscan Memory Usage
Rreplace - How to Replace the Last Occurrence of an Expression in a String
General Unicode/Utf-8 Support for CSV Files in Python 2.6
How to Invoke Pandas.Rolling.Apply with Parameters from Multiple Column
Failed to Upload Packages to Pypi: 410 Gone
Finding the Consecutive Zeros in a Numpy Array
Python: Dynamically Create Function at Runtime
Schedule a Repeating Event in Python 3
Replace Nth Occurrence of Substring in String
Use a Library Locally Instead of Installing It