【问题标题】:ftplib - 504 Security mechanism 'TLS' not implementedftplib - 504 未实施安全机制“TLS”
【发布时间】:2015-08-03 11:02:50
【问题描述】:

我正在尝试使用ftplib 连接到安全 FTP,但由于某种原因它不起作用(尝试连接到 www.sharefile.com ftp。它说使用此地址:company.sharefileftp.com )

我正在尝试这种方法 (FTPES - FTP over explicit TLS/SSL in Python):

from ftplib import FTP_TLS
ftps = FTP_TLS('company.sharefileftp.com')
ftps.login('user', 'pass')           # 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()

但它给了我这个错误(调用此行时ftps.login('testuser', 'testpass')):

error_perm                                Traceback (most recent call last)
<ipython-input-17-bfe01179f1c2> in <module>()
----> ftps.login('user', 'pass')

/usr/lib/python2.7/ftplib.pyc in login(self, user, passwd, acct, secure)
    650         def login(self, user='', passwd='', acct='', secure=True):
    651             if secure and not isinstance(self.sock, ssl.SSLSocket):
--> 652                 self.auth()
    653             return FTP.login(self, user, passwd, acct)
    654 

/usr/lib/python2.7/ftplib.pyc in auth(self)
    658                 raise ValueError("Already using TLS")
    659             if self.ssl_version == ssl.PROTOCOL_TLSv1:
--> 660                 resp = self.voidcmd('AUTH TLS')
    661             else:
    662                 resp = self.voidcmd('AUTH SSL')

/usr/lib/python2.7/ftplib.pyc in voidcmd(self, cmd)
    252         """Send a command and expect a response beginning with '2'."""
    253         self.putcmd(cmd)
--> 254         return self.voidresp()
    255 
    256     def sendport(self, host, port):

/usr/lib/python2.7/ftplib.pyc in voidresp(self)
    227     def voidresp(self):
    228         """Expect a response beginning with '2'."""
--> 229         resp = self.getresp()
    230         if resp[:1] != '2':
    231             raise error_reply, resp

/usr/lib/python2.7/ftplib.pyc in getresp(self)
    222             raise error_temp, resp
    223         if c == '5':
--> 224             raise error_perm, resp
    225         raise error_proto, resp
    226 

error_perm: 504 Security mechanism 'TLS' not implemented.

P.S.但我可以使用 FTP 连接(不是安全的):

>>> from ftplib import FTP
>>> ftp = FTP('company.sharefileftp.com')     # connect to host, default port
>>> ftp.login('user', 'pass')                     # user anonymous, passwd anonymous@

【问题讨论】:

    标签: python ssl ftp ftplib


    【解决方案1】:

    服务器根本不支持 TLS,旧的“AUTH SSL”和新的“AUTH TLS”都不支持。此问题与 python 无关,因为以下 telnet 测试显示:

    $telnet company.sharefileftp.com 21
    Trying 54.194.108.219...
    Connected to company.sharefileftp.com.
    Escape character is '^]'.
    220 ftp-eu-1.sharefileftp.com FTP Server Ready
    AUTH TLS
    504 Security mechanism 'TLS' not implemented.
    AUTH SSL
    504 Security mechanism 'SSL' not implemented.
    QUIT
    221-Sent: 142 bytes   Rcvd: 26 bytes   Time: 15s
    221 ftp-eu-1.sharefileftp.com session ended.
    Connection closed by foreign host.
    

    但它确实支持(旧的且从未标准化的)隐式 TLS:

    $ openssl s_client -connect company.sharefileftp.com:990
    ...
    SSL-Session:
        Protocol  : TLSv1
       Cipher    : RC4-SHA
    ...
    220 ftp-eu-1.sharefileftp.com FTP Server Ready (SSL)
    

    【讨论】:

      【解决方案2】:

      您正在使用显式 TLS/SSL 进行连接(通常是推荐的模式)。

      sharefile.com 似乎只支持隐式 TLS/SSL(这很不寻常)。

      相反,ftplib 似乎不支持开箱即用的隐式 TLS/SSL。

      你可以修复它。查看回复:
      Python FTP implicit TLS connection issue

      【讨论】:

        猜你喜欢
        • 2016-10-07
        • 2020-06-09
        • 1970-01-01
        • 2017-11-14
        • 2013-05-18
        • 1970-01-01
        • 1970-01-01
        • 2018-02-24
        • 1970-01-01
        相关资源
        最近更新 更多