Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python FTPS以被动模式挂起在目录列表上_Python_Curl_Ftp_Ftplib - Fatal编程技术网

Python FTPS以被动模式挂起在目录列表上

Python FTPS以被动模式挂起在目录列表上,python,curl,ftp,ftplib,Python,Curl,Ftp,Ftplib,我设法使用curl连接到FTP服务器,并列出目录的内容out: $ curl -v --insecure --ftp-ssl --user xxx:yyy blabla:990/out/ > AUTH SSL < 234 Proceed with negotiation. ... > USER xxx < 331 Please specify the password. > PASS yyy < 230 Login successful. > PBSZ

我设法使用curl连接到FTP服务器,并列出目录的内容
out

$ curl -v --insecure --ftp-ssl --user xxx:yyy blabla:990/out/
> AUTH SSL
< 234 Proceed with negotiation.
...
> USER xxx
< 331 Please specify the password.
> PASS yyy
< 230 Login successful.
> PBSZ 0
< 200 PBSZ set to 0.
> PROT P
< 200 PROT now Private.
> PWD
< 257 "/"
> CWD out
< 250 Directory successfully changed.
> EPSV
< 229 Entering Extended Passive Mode (|||51042|).
*   Trying aaa.bbb.ccc.ddd...
* Connecting to aaa.bbb.ccc.ddd (aaa.bbb.ccc.ddd) port 51042
* Connected to blabla (aaa.bbb.ccc.ddd) port 990 (#0)
> TYPE A
< 200 Switching to ASCII mode.
> LIST
< 150 Here comes the directory listing.
* Maxdownload = -1
* Doing the SSL/TLS handshake on the data stream
* SSL re-using session ID
* TLS 1.0 connection using TLS_RSA_WITH_AES_256_CBC_SHA
* Server certificate: blabla
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
{ [539 bytes data]
100   539    0   539    0     0    900      0 --:--:-- --:--:-- --:--:--   899* Remembering we are in dir "out/"
< 226 Directory send OK.
但是在python中,
LIST命令无限期地挂起

*cmd* 'AUTH TLS'
*resp* '234 Proceed with negotiation.'
*cmd* 'USER xxx'
*resp* '331 Please specify the password.'
*cmd* 'PASS ********\n'
*resp* '230 Login successful.'
230 Login successful.
*cmd* 'PBSZ 0'
*resp* '200 PBSZ set to 0.'
200 PBSZ set to 0.
*cmd* 'PBSZ 0'
*resp* '200 PBSZ set to 0.'
*cmd* 'PROT P'
*resp* '200 PROT now Private.'
200 PROT now Private.
*cmd* 'PWD'
*resp* '257 "/"'
/
*cmd* 'CWD out'
*resp* '250 Directory successfully changed.'
250 Directory successfully changed.
*cmd* 'PASV'
*resp* '227 Entering Passive Mode (aa,bb,cc,dd,199,97).'
为什么会发生这种情况

更新:好的,我在curl命令中添加了选项
--disable epsv
,这也失败了。因此,python无法列出目录的原因是它使用了
PASV
。如何强制Python使用
EPSV


UPDATE2:当PASV返回的IP地址错误时,此错误似乎会导致Python ftplib挂起。这似乎也是我的问题所在。但是有人知道如何强制Python使用
EPSV
来代替吗?

通过阅读我的源代码,可以通过设置

ftps.af = socket.AF_INET6
这使ftplib认为我们使用的是IPv6连接(即使我们实际上使用的是IPv4),并使其使用
EPSV
而不是
PASV
。我的全部工作计划终于完成了

import ftplib
import socket

ftps = ftplib.FTP_TLS()

ftps.connect("blabla", 990)
ftps.login("xxx", "yyy")
ftps.prot_p()
ftps.cwd("out")
ftps.af = socket.AF_INET6
ftps.retrlines("LIST")
ftps.quit()

通过阅读我的源代码,可以通过设置

ftps.af = socket.AF_INET6
这使ftplib认为我们使用的是IPv6连接(即使我们实际上使用的是IPv4),并使其使用
EPSV
而不是
PASV
。我的全部工作计划终于完成了

import ftplib
import socket

ftps = ftplib.FTP_TLS()

ftps.connect("blabla", 990)
ftps.login("xxx", "yyy")
ftps.prot_p()
ftps.cwd("out")
ftps.af = socket.AF_INET6
ftps.retrlines("LIST")
ftps.quit()