【问题标题】:Python SSL FTP connection timing outPython SSL FTP 连接超时
【发布时间】:2013-12-07 18:49:38
【问题描述】:

我正在尝试从 Python (v3.3.0) 中使用 SSL 建立与 FTP 服务器的连接。但我一直在超时。我使用端口 990 作为 SSL 端口(偏执)。那会是这个问题的原因吗?如果是这样,我如何指定我正在使用的端口?

这是我的脚本:

    from ftplib import FTP
    from ftplib import FTP_TLS

    ftps = FTP_TLS('ip address')

    ftps.auth()

    ftps.sendcmd('USER uname') 
    ftps.sendcmd('PASS password')

    ftps.prot_p()
    ftps.retrlines('LIST')

    ftps.close()

结果如下:

Traceback (most recent call last):
  File "Scrpit name removed for posting", line 12, in <module>
    ftps.retrlines('LIST')
  File "C:\Python33\lib\ftplib.py", line 767, in retrlines
    conn = self.transfercmd(cmd)
  File "C:\Python33\lib\ftplib.py", line 381, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python33\lib\ftplib.py", line 742, in ntransfercmd
    conn, size = FTP.ntransfercmd(self, cmd, rest)
  File "C:\Python33\lib\ftplib.py", line 343, in ntransfercmd
    source_address=self.source_address)
  File "C:\Python33\lib\socket.py", line 424, in create_connection
    raise err
  File "C:\Python33\lib\socket.py", line 415, in create_connection
   sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

任何建议将不胜感激,

【问题讨论】:

    标签: python ssl ftp timeout


    【解决方案1】:

    看了ftplib source之后,好像除了21什么端口都不想用。

    我认为你应该能够解决这个问题,比如

    import ftplib
    
    ftplib.FTP.port = 995     # or whatever port you are using
    ftps = ftplib.FTP_TLS('hostname', 'user', 'pwd')
    ftps.retrlines('LIST')
    

    【讨论】:

    • 谢谢 - 在谷歌搜索解决方案后,我终于找到了解决问题的答案。我现在可以获得目录列表!
    【解决方案2】:

    通过connect设置端口

    import ftplib
    
    ftps = ftplib.FTP_TLS()
    ftps.connect ('hostname', 991)
    

    【讨论】:

    • 我使用非标准端口 21 进行 FTP,但没有使用标准端口 990 进行 SSL,那么我将如何设置 SSL 端口?
    • 据我所知,使用上述方法连接到指定端口。
    • 为了隔离问题,我把SSL端口改成了默认的990,但是还是有同样的超时问题。我通过 Filezilla 客户端手动连接验证了端口更改
    猜你喜欢
    • 2015-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 1970-01-01
    • 2015-06-05
    • 1970-01-01
    相关资源
    最近更新 更多