I'm having problems with FTP_TLS (ftplib) in Python 2.7.3.
Summary of findings (all connection attempts performed over the internet):
- FileZilla to home web server - works
- FileZilla to GoDaddy shared hosting server - works
- Python to home web server - works
- Python to GoDaddy shared hosting server - fails (see stack trace below)
The following code shows how I reproduce the problem. When connecting to my home server, this code generates an identical log on my personal FTP as FileZilla. (Only when connecting to the GoDaddy site does it result in an EOF exception).
from ftplib import FTP_TLS
o = FTP_TLS(ftpServer,ftpUsername,ftpPassword,ftpPort)
o.voidcmd('SYST')
o.voidcmd('FEAT')
o.prot_p()
o.voidcmd('PWD')
o.retrbinary('MLSD', open('OUTTEST', 'wb').write)
>>> o.retrbinary('MLSD', open('OUTTEST', 'wb').write)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/ftplib.py", line 703, in retrbinary
return self.voidresp()
File "/usr/lib/python2.7/ftplib.py", line 225, in voidresp
resp = self.getresp()
File "/usr/lib/python2.7/ftplib.py", line 211, in getresp
resp = self.getmultiline()
File "/usr/lib/python2.7/ftplib.py", line 197, in getmultiline
line = self.getline()
File "/usr/lib/python2.7/ftplib.py", line 187, in getline
if not line: raise EOFError
I read that the EOF error is given when the server closes the pipe. It's also similar to what happens if you change to prot_p and then try to issue a plain text command (although as far as I can tell, this isn't the case here).
I don't understand what's different between my code and FileZilla. The fact that all attempts are performed over the internet reassures me that it isn't related to firewalls. Furthermore, FileZilla works, so from a technical perspective the connection is possible, I'm just having a hard time achieving it with Python.
My code works with the GoDaddy FTP if I don't issue the prot_p switch.
Additional information:
- GoDaddy doesn't provide technical FTP logs (only usage logs)
- My code has been working flawlessly for over a year, this just started happening two months ago.
- The GoDaddy FTP server identifies as "Pure-FTPd [privsep] [TLS]"
Typical FileZilla Server Log after running my code.
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> Connected on port 21, sending welcome message...
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220-FileZilla Server 0.9.57 beta
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220-written by Tim Kosse (Tim.Kosse@gmx.de)
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 220 Please visit https://filezilla-project.org/
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> AUTH TLS
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 234 Using authentication type TLS
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> SSL connection established
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> USER ********************
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> 331 Password required for USER_NAME
(000132)18/10/2016 15:44:19 - (not logged in) (IP_ADDRESS)> PASS ********************
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 230 Logged on
(000131)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> disconnected.
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> SYST
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 215 UNIX emulated by FileZilla
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> FEAT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 211-Features:
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MDTM
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> REST STREAM
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> SIZE
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MODE Z
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MLST type*;size*;modify*;
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MLSD
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> AUTH SSL
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> AUTH TLS
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PROT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PBSZ
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> UTF8
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> CLNT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> MFMT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> EPSV
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> EPRT
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 211 End
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PBSZ 0
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 200 PBSZ=0
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PROT P
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 200 Protection level set to P
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> PWD
(000132)18/10/2016 15:44:19 - USER_NAME (IP_ADDRESS)> 257 "/" is current directory.
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> TYPE I
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 200 Type set to I
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> PASV
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 227 Entering Passive Mode (xxx,xxx,xxx,xxx,xxx,xxx)
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> MLSD
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 150 Opening data channel for directory listing of "/"
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> SSL connection for data connection established
(000132)18/10/2016 15:44:22 - USER_NAME (IP_ADDRESS)> 226 Successfully transferred "/"