[英]FTPES - FTP over explicit TLS/SSL in Python
我需要一个 python 客户端来执行 FTPES(显式),是否有人对任何可以执行此操作的 python 包有经验。
我无法在 python 中执行此操作,但可以使用 FileZilla 等工具连接到 FTP 服务器
谢谢
本机 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')
# 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()
标准 ftplib 确实包含 ftpes(ftps 显式)连接所需的一切。 我没有找到简单的方法来建立隐式连接。
请参阅: http ://docs.python.org/2/library/ftplib.html#ftplib.FTP_TLS
我需要一个 python 客户端来执行 FTPES(显式),是否有人对任何可以执行此操作的 python 包有经验。
stdlib
中的ftplib
应该做你想做的事......一个例子,从文档中提取......
>>> 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()
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.