Python SSL FTP 连接超时

标签 python ssl ftp timeout

我正在尝试从 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

如有任何建议,我们将不胜感激,

最佳答案

查看 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')

关于Python SSL FTP 连接超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20152504/

相关文章:

Python 在字符串中使用通配符

python - 模块导入和 __init__.py

linux - SSL 和 Tkinter 不存在于 Python 3.5.2、Debian Linux 的源代码构建中

ios - 在 iPhone 应用程序中使用 SSL - 导出合规

asp.net - 如何完全编写导入 SSL 证书并将此证书绑定(bind)到特定站点的过程的脚本

iphone - 使用 iPhone 应用程序将照片上传到任意 FTP

javascript - gulp.watch() 不适用于 ftp 更新

vb.net - VS2015 : The components for communicating with FTP servers are not installed

Python:使用多处理进行并行图像读取和预处理

python - 在执行期间更改 Spark Streaming 中的批量大小