ftplib: socket.error during/after LIST//ssl._sslobj.shutdown()/连接超时 [英] ftplib: socket.error during/after LIST // ssl._sslobj.shutdown() / connection timed out

查看:75
本文介绍了ftplib: socket.error during/after LIST//ssl._sslobj.shutdown()/连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用客户端证书连接到 FTPS 服务器.
我尝试了 2 个不同的服务器(我无法控制,但应该非常相似).

连接建立,PWD命令成功.
在一台服务器上,LIST 命令成功,但在第二台服务器上,它产生正确的结果(文件列表),但之后(显然是在 SSL 关闭期间)产生错误.
在服务器端,他们告诉我:您的 LIST 命令正在正确传递,但随后您在新的 SSL 重新协商期间断开了连接."
知道为什么吗?

提前致谢.

.

建立连接的常用命令:

# Python 2.7.3rc2(默认,2012 年 4 月 22 日,22:30:17)>>>导入 ssl>>>从 ftplib 导入 FTP_TLS>>>ftps = FTP_TLS(keyfile="/path/to/***.key", certfile="/path/to/***.crt")>>>ftps.set_debuglevel(2)>>>ftps.ssl_version = ssl.PROTOCOL_TLSv1>>>ftps.connect("***", 7806)*get* '220 欢迎使用同步网关 FTP 服务器\r\n'*resp* '220 欢迎使用同步网关 FTP 服务器''220 欢迎使用同步网关 FTP 服务器'>>>ftps.auth()*cmd* 'AUTH TLS'*put* 'AUTH TLS\r\n'*get* '234 AUTH 命令正常,等待握手\r\n'*resp* '234 AUTH 命令正常,等待握手''234 AUTH 命令正常,等待握手'>>>ftps.login("***", "***")*cmd* '用户 ***'*put* '用户 ***\r\n'*get* '331 请发送密码\r\n'*resp* '331 请发送密码'*cmd* '通过 ************'*put* '通过 ************\r\n'*get* '230 用户登录,继续\r\n'*resp* '230 用户登录,继续''230 用户登录,继续'>>>ftps.prot_p()*cmd* 'PBSZ 0'*放* 'PBSZ 0\r\n'*get* '200 命令正常\r\n'*resp* '200 命令没问题'*cmd* '保护 P'*put* 'PROT P\r\n'*get* '200 命令正常\r\n'*resp* '200 命令没问题''200 命令没问题'>>>ftps.set_pasv(真)>>>ftps.pwd()*cmd* '密码'*put* '密码\r\n'*get* '257 "/" 是当前目录.\r\n'*resp* '257 "/" 是当前目录.''/'

.

失败的 LIST 命令:

<预><代码>>>>ftps.retrlines("列表")*cmd* 'TYPE A'*put* 'TYPE A\r\n'*get* '200 命令正常\r\n'*resp* '200 命令没问题'*cmd* 'PASV'*put* 'PASV\r\n'*get* '227 进入被动模式(212,63,***,**,30,131).\r\n'*resp* '227 进入被动模式 (212,63,***,**,30,131).'*cmd* '列表'*put* '列表\r\n'*get* '125 列表已启动\r\n'*resp* '125 列表开始'共 3 个dr-xr-xr-x 0 --NA-- --NA-- 0 4 月 23 日 16:46.d--------- 0 --NA-- --NA-- 0 Jun 4 15:02 ..dr-xr-xr-x 0 --NA-- --NA-- 0 4 月 23 日 16:46 **回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>文件/usr/lib/python2.7/ftplib.py",第 721 行,在 retrlines 中conn.unwrap()文件/usr/lib/python2.7/ssl.py",第 284 行,在解包中s = self._sslobj.shutdown()socket.error: [Errno 0] 错误>>>ftps.pwd()*cmd* '密码'*put* '密码\r\n'*get* '226 列表已完成\r\n'*resp* '226 列表已完成'回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>文件/usr/lib/python2.7/ftplib.py",第575行,密码返回 parse257(resp)文件/usr/lib/python2.7/ftplib.py",第 839 行,在 parse257 中引发 error_reply,respftplib.error_reply: 226 列表已完成>>>ftps.quit()*cmd* '退出'*put* '退出\r\n'*get* '257 "/" 是当前目录.\r\n'*resp* '257 "/" 是当前目录.''257 "/" 是当前目录.'

解决方案

我们也面临同样的问题.SSL.PY 内我们收到错误 0 异常

def unwrap(self):如果 self._sslobj:打印SSL 对象存在"s = self._sslobj.shutdown()打印SSL 对象关闭"打印打印s"印刷self._sslobj = 无返回别的:raise ValueError("没有 SSL 包装器" + str(self))

s = self._sslobj.shutdown() 在这一行抛出异常.你有这方面的更新吗?

我用下面的代码修改了 ftplib.py retrline 方法

 if isinstance(conn, ssl.SSLSocket):conn.close()

它的工作没有任何错误.我不知道此更改对其他功能的影响

I try to connect to a FTPS server using a client certificate.
I tried on 2 different servers (over which I've no control but that should be quite similar).

The connection is established and the PWD command succeeds.
On one server the LIST command succeed but on the second one, it produces the right result (the list of files) but generates an error after (apparently during the SSL shutdown).
On the server side, they told me: "Your LIST command is passing correctly but afterward you loose the connection during a new SSL re-negociation."
Any idea why?

Thanks in advance.

.

The common commands to establish the connection:

# Python 2.7.3rc2 (default, Apr 22 2012, 22:30:17)

>>> import ssl
>>> from ftplib import FTP_TLS

>>> ftps = FTP_TLS(keyfile="/path/to/***.key", certfile="/path/to/***.crt")
>>> ftps.set_debuglevel(2)
>>> ftps.ssl_version = ssl.PROTOCOL_TLSv1
>>> ftps.connect("***", 7806)
*get* '220 Welcome to Synchrony Gateway FTP server\r\n'
*resp* '220 Welcome to Synchrony Gateway FTP server'
'220 Welcome to Synchrony Gateway FTP server'

>>> ftps.auth()
*cmd* 'AUTH TLS'
*put* 'AUTH TLS\r\n'
*get* '234 AUTH command OK, waiting handshake\r\n'
*resp* '234 AUTH command OK, waiting handshake'
'234 AUTH command OK, waiting handshake'

>>> ftps.login("***", "***")
*cmd* 'USER ***'
*put* 'USER ***\r\n'
*get* '331 Send password please\r\n'
*resp* '331 Send password please'
*cmd* 'PASS ************'
*put* 'PASS ************\r\n'
*get* '230 User logged in, proceed\r\n'
*resp* '230 User logged in, proceed'
'230 User logged in, proceed'

>>> ftps.prot_p()
*cmd* 'PBSZ 0'
*put* 'PBSZ 0\r\n'
*get* '200 Command okay\r\n'
*resp* '200 Command okay'
*cmd* 'PROT P'
*put* 'PROT P\r\n'
*get* '200 Command okay\r\n'
*resp* '200 Command okay'
'200 Command okay'

>>> ftps.set_pasv(True)
>>> ftps.pwd()
*cmd* 'PWD'
*put* 'PWD\r\n'
*get* '257 "/" is current directory.\r\n'
*resp* '257 "/" is current directory.'
'/'

.

The LIST command that fails:

>>> ftps.retrlines("LIST")
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Command okay\r\n'
*resp* '200 Command okay'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering passive mode (212,63,***,**,30,131).\r\n'
*resp* '227 Entering passive mode (212,63,***,**,30,131).'
*cmd* 'LIST'
*put* 'LIST\r\n'
*get* '125 List started\r\n'
*resp* '125 List started'
total 3
dr-xr-xr-x   0 --NA--   --NA--            0 Apr 23 16:46 .
d---------   0 --NA--   --NA--            0 Jun  4 15:02 ..
dr-xr-xr-x   0 --NA--   --NA--            0 Apr 23 16:46 **
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ftplib.py", line 721, in retrlines
    conn.unwrap()
  File "/usr/lib/python2.7/ssl.py", line 284, in unwrap
    s = self._sslobj.shutdown()
socket.error: [Errno 0] Error

>>> ftps.pwd()
*cmd* 'PWD'
*put* 'PWD\r\n'
*get* '226 List completed\r\n'
*resp* '226 List completed'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/ftplib.py", line 575, in pwd
    return parse257(resp)
  File "/usr/lib/python2.7/ftplib.py", line 839, in parse257
    raise error_reply, resp
ftplib.error_reply: 226 List completed

>>> ftps.quit()
*cmd* 'QUIT'
*put* 'QUIT\r\n'
*get* '257 "/" is current directory.\r\n'
*resp* '257 "/" is current directory.'
'257 "/" is current directory.'

解决方案

We are also facing the same problem. inside SSL.PY we are geting error 0 exception

def unwrap(self):
    if self._sslobj:
        print "SSL Object Present"
        s = self._sslobj.shutdown()
        print "SSL Object Shoutdown"
        print "print s"
        print s
        self._sslobj = None
        return s
    else:
        raise ValueError("No SSL wrapper around " + str(self))

s = self._sslobj.shutdown() on this line its throwing exception. do you have nay update on this?

I modified the ftplib.py retrline method with below code

    if isinstance(conn, ssl.SSLSocket):
     conn.close()

its working with out any error. I don't know impact of this changes in other functionality

这篇关于ftplib: socket.error during/after LIST//ssl._sslobj.shutdown()/连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆