I'm trying to connect to Secure FTP using ftplib
, but it does not work for some reason (trying to connect to www.sharefile.com ftp. there it says to use this address: company.sharefileftp.com)
I'm trying this approach (FTPES - FTP over explicit TLS/SSL in Python):
from ftplib import FTP_TLS
ftps = FTP_TLS('company.sharefileftp.com')
ftps.login('user', 'pass') # login anonymously before securing control channel
ftps.prot_p() # switch to secure data connection.. IMPORTANT! Otherwise, only the user and password is encrypted and not all the file data.
ftps.retrlines('LIST')
filename = 'remote_filename.bin'
print 'Opening local file ' + filename
myfile = open(filename, 'wb')
ftps.retrbinary('RETR %s' % filename, myfile.write)
ftps.close()
But it gives me this error (when calling this line ftps.login('testuser', 'testpass')
):
error_perm Traceback (most recent call last)
<ipython-input-17-bfe01179f1c2> in <module>()
----> ftps.login('user', 'pass')
/usr/lib/python2.7/ftplib.pyc in login(self, user, passwd, acct, secure)
650 def login(self, user='', passwd='', acct='', secure=True):
651 if secure and not isinstance(self.sock, ssl.SSLSocket):
--> 652 self.auth()
653 return FTP.login(self, user, passwd, acct)
654
/usr/lib/python2.7/ftplib.pyc in auth(self)
658 raise ValueError("Already using TLS")
659 if self.ssl_version == ssl.PROTOCOL_TLSv1:
--> 660 resp = self.voidcmd('AUTH TLS')
661 else:
662 resp = self.voidcmd('AUTH SSL')
/usr/lib/python2.7/ftplib.pyc in voidcmd(self, cmd)
252 """Send a command and expect a response beginning with '2'."""
253 self.putcmd(cmd)
--> 254 return self.voidresp()
255
256 def sendport(self, host, port):
/usr/lib/python2.7/ftplib.pyc in voidresp(self)
227 def voidresp(self):
228 """Expect a response beginning with '2'."""
--> 229 resp = self.getresp()
230 if resp[:1] != '2':
231 raise error_reply, resp
/usr/lib/python2.7/ftplib.pyc in getresp(self)
222 raise error_temp, resp
223 if c == '5':
--> 224 raise error_perm, resp
225 raise error_proto, resp
226
error_perm: 504 Security mechanism 'TLS' not implemented.
P.S. But I can connect using FTP (not secure one):
>>> from ftplib import FTP
>>> ftp = FTP('company.sharefileftp.com') # connect to host, default port
>>> ftp.login('user', 'pass') # user anonymous, passwd anonymous@