实现ftps的Python模块

2024-04-28 04:24:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否有人能给我介绍一个免费的用于python的ftps模块。

我是python的新手,但这是我工作项目所需要的。我需要一个ftps客户端来连接到第三方ftps服务器。

谢谢

大卫。


Tags: 模块项目服务器客户端大卫新手ftps
3条回答

M2Cypto有一个FTPS模块。从documentation

>>> from M2Crypto import ftpslib
>>> f = ftpslib.FTP_TLS()
>>> f.connect('', 9021)
'220 spinnaker.dyndns.org M2Crypto (Medusa) FTP/TLS server v0.07 ready.'
>>> f.auth_tls()
>>> f.set_pasv(0)
>>> f.login('ftp', 'ngps@')
'230 Ok.'
>>> f.retrlines('LIST')
-rw-rw-r--   1 0        198          2326 Jul  3  1996 apache_pb.gif
drwxrwxr-x   7 0        198          1536 Oct 10  2000 manual
drwxrwxr-x   2 0        198           512 Oct 31  2000 modpy
drwxrwxr-x   2 0        198           512 Oct 31  2000 bobo
drwxr-xr-x   2 0        198         14336 May 28 15:54 postgresql
drwxr-xr-x   4 100      198           512 May 16 17:19 home
drwxr-xr-x   7 100      100          3584 Sep 23  2000 openacs
drwxr-xr-x  10 0        0             512 Aug  5  2000 python1.5
-rw-r--r--   1 100      198           326 Jul 29 03:29 index.html
drwxr-xr-x  12 0        0             512 May 31 17:08 python2.1
'226 Transfer complete'
>>> f.quit()
'221 Goodbye.'
>>>

或者,如果您希望尽量减少对第三方模块的使用,那么应该能够使用内置(到Python)SSL支持对标准库的ftplib.FTP类进行子类化。不过,M2Crypto(或者Twisted,如果你想这样做的话)是更简单的解决方案。

Python 2.7.1版本中的ftplib模块具有您需要的所有功能,包括TLS支持。

http://docs.python.org/library/ftplib.html#module-ftplib

我相信您可以使用Twisted来实现FTPS,方法是简单地使用它的FTP实现,但是将^{}属性更改为使用^{}而不是connectTCP执行某些操作的函数。

你确定你想要FTPS吗?SFTP is a different, better, and much more popular protocol现在:Twisted也包含an SFTP implementation

相关问题 更多 >