FTPES - 在Python中通过显式TLS/SSL进行FTP

use*_*060 15 python ftp tcp ftpes

我需要一个python客户端来做FTPES(显式),有没有人有任何python包可以做到这一点的经验.

我无法在python中执行此操作,但可以使用FileZilla等工具连接到FTP服务器

谢谢

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)

  • 但是,对于需要在数据通道中重用TLS会话的服务器,需要将FTP_TLS子类化,请参见此处的解决方法:/sf/answers/3031122531/。 (3认同)
  • 多谢!我一整天都收到“ftplib.error_perm:534策略需要SSL”,通过使用“.prot_p()”切换到安全数据连接来解决。 (3认同)

use*_*394 7

对我来说,这有效:(在身份验证后登录)。取自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)


Mik*_*ton 0

我需要一个 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)