Python FTP目录列表挂起
在谷歌上进行了大量搜索,并审查了许多stackoverflow问题之后,我仍然不知所措。我尝试获取目录列表的每个方法都以Python发送两个命令(键入a和PASV)结束,然后它就停止了说话。有什么建议吗 我的Python(2.7.6)代码: 输出:Python FTP目录列表挂起,python,list,ftp,ftplib,Python,List,Ftp,Ftplib,在谷歌上进行了大量搜索,并审查了许多stackoverflow问题之后,我仍然不知所措。我尝试获取目录列表的每个方法都以Python发送两个命令(键入a和PASV)结束,然后它就停止了说话。有什么建议吗 我的Python(2.7.6)代码: 输出: *resp* '220 Microsoft FTP Service' *welcome* '220 Microsoft FTP Service' *cmd* 'USER c680-750' *resp* '331 Password required
*resp* '220 Microsoft FTP Service'
*welcome* '220 Microsoft FTP Service'
*cmd* 'USER c680-750'
*resp* '331 Password required for c680-750'
*cmd* 'PASS *******'
*resp* '230 User c680-750 logged in'
==Getting DIR...
*cmd* 'TYPE A'
*resp* '200 Command okay.'
*cmd* 'PASV'
*resp* '227 Entering Passive Mode (204,77,162,69,218,190)' Traceback (most recent call last): ...
raise err error: [Errno 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
FileZilla在成功连接时所说的:
Status: Resolving address of xxxx
Status: Connecting to xxx.xx.xxx.xx:21...
Status: Connection established, waiting for welcome message...
Response: 220 Microsoft FTP Service
Command: USER xxxx
Response: 331 Password required for xxxx
Command: PASS *******
Response: 230 User xxxx logged in
Command: SYST
Response: 215 UNIX Type: L8
Command: FEAT
Response: 211-Extensions supported:
Response: MDTM
Response: SIZE
Response: 211 END
Status: Server does not support non-ASCII characters.
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "xxxx" is the current directory
Command: TYPE I
Response: 200 Command okay.
Command: PORT 167,186,116,227,234,64
Response: 200 PORT command successful.
Command: LIST
Response: 150 File status okay; about to open data connection.
Response: 226 Transfer complete, closing data connection.
Status: Directory listing successful
FileZilla使用的是活动模式(端口),在该模式下,从服务器到客户端建立数据连接。您的python代码使用PASV模式,在这种模式下,数据连接是从客户端到服务器建立的。在python中使用被动模式
ftp.set_pasv(False)
虽然通常首选被动模式,因为如果客户端位于某个NAT路由器后面(即在家中的典型设置),被动模式可以工作,但如果服务器本身位于某个防火墙或NAT设备后面,则被动模式可能会失败。在这种情况下,您需要使用活动模式。。非常感谢。
ftp.set_pasv(False)