Sil*_*eel 16
本机Python很好地支持FTP-SSL Explicit.设置连接后,您可以使用所有标准ftplib命令.更多信息请访问:http: //docs.python.org/2/library/ftplib.html#ftplib.FTP_TLS
这是下载文件的基本示例:
from ftplib import FTP_TLS
ftps = FTP_TLS('ftp.MySite.com')
ftps.login('testuser', 'testpass') # 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()
Run Code Online (Sandbox Code Playgroud)
对我来说,这有效:(在身份验证后登录)。取自Nullege。它们似乎是对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)
Run Code Online (Sandbox Code Playgroud)
我需要一个 python 客户端来执行 FTPES(显式),是否有人有任何可以执行此操作的 python 包的经验。
ftplib应该stdlib做你想做的...一个例子,从文档中摘取...
>>> 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()
>>>
Run Code Online (Sandbox Code Playgroud)