我正在尝试使用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
任何建议都将不胜感激,
答案 0 :(得分:3)
在查看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')
答案 1 :(得分:0)
通过connect
import ftplib
ftps = ftplib.FTP_TLS()
ftps.connect ('hostname', 991)