开发者

FTPES - FTP over explicit TLS/SSL in Python

I need a python client to do FTPES (explicit), does anyone has experience with any python package that can do this.

I am not able to do this in pyt开发者_如何学运维hon, but can connect to FTP server using tools like FileZilla

Thanks


FTP-SSL Explicit is well supported by native Python. After setting up the connection, you can use all the standard ftplib commands. More can be found at: http://docs.python.org/2/library/ftplib.html#ftplib.FTP_TLS

Here's a basic example for downloading a file:

from ftplib import FTP_TLS
ftps = FTP_TLS('ftp.MySite.com')
# login after securing control channel
ftps.login('testuser', 'testpass')           
# switch to secure data connection.. 
# IMPORTANT! Otherwise, only the user and password is encrypted and
# not all the file data.
ftps.prot_p()          
ftps.retrlines('LIST')

filename = 'remote_filename.bin'
print 'Opening local file ' + filename
with open(filename, 'wb') as myfile:
    ftps.retrbinary('RETR %s' % filename, myfile.write)

ftps.close()


For me this worked: (login after auth). Taken from Nullege. They seem to be tests for ftplib.

self.client = ftplib.FTP_TLS(timeout=10)
self.client.connect(self.server.host, self.server.port)

# enable TLS
self.client.auth()
self.client.prot_p()

self.client.login(user,pass)


Standard ftplib does contain everything you need for ftpes (ftps explicit) connection. I didn't find easy way to make implicit connections.

See: http://docs.python.org/2/library/ftplib.html#ftplib.FTP_TLS


I need a python client to do FTPES (explicit), does anyone has experience with any python package that can do this.

ftplib in stdlib should do what you want... an example, lifted from the docs...

>>> from ftplib import FTP_TLS
>>> from getpass import getpass
>>>
>>> ftpes = FTP_TLS('ftp.cisco.com', timeout=5)
>>> passwd = getpass("Enter your password:")
Enter your password:
>>> ftpes.login("username", passwd)   # login before securing channel
>>> ftpes.prot_p()          # switch to secure data connection
>>> ftpes.retrlines('LIST') # list directory content securely
total 9
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 .
drwxr-xr-x   8 root     wheel        1024 Jan  3  1994 ..
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 bin
drwxr-xr-x   2 root     wheel        1024 Jan  3  1994 etc
d-wxrwxr-x   2 ftp      wheel        1024 Sep  5 13:43 incoming
drwxr-xr-x   2 root     wheel        1024 Nov 17  1993 lib
drwxr-xr-x   6 1094     wheel        1024 Sep 13 19:07 pub
drwxr-xr-x   3 root     wheel        1024 Jan  3  1994 usr
-rw-r--r--   1 root     root          312 Aug  1  1994 welcome.msg
'226 Transfer complete.'
>>> filename = "welcome.msg"
>>> ftpes.retrbinary('RETR %s' % filename, open(filename, 'wb').write)
'226 Transfer complete.'
>>> ftpes.close()
>>>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜