ftp无法与服务器建立连接_FTP连接错误:Failed to retrieve directory listing 解决办法

更新时间:2019-10-02    来源:手机软件    手机版     字体:

【www.bbyears.com--手机软件】

在服务器上用vsftp软件建立了FTP服务,但是在使用FillaZilla客户端连接该FTP时,却出现了如下的错误信息服务:

 代码如下 Status:    Resolving address of smilejay.com
Status:    Connecting to 192.3.170.172:21...
Status:    Connection established, waiting for welcome message...
Response:    220 (vsFTPd 2.2.2)
Command:    USER anonymous
Response:    331 Please specify the password.
Command:    PASS **************
Response:    230 Login successful.
Command:    SYST
Response:    215 UNIX Type: L8
Command:    FEAT
Response:    211-Features:
Response:     EPRT
Response:     EPSV
Response:     MDTM
Response:     PASV
Response:     REST STREAM
Response:     SIZE
Response:     TVFS
Response:     UTF8
Response:    211 End
Command:    OPTS UTF8 ON
Response:    200 Always in UTF8 mode.
Status:    Connected
Status:    Retrieving directory listing...
Command:    PWD
Response:    257 "/"
Command:    TYPE I
Response:    200 Switching to Binary mode.
Command:    PAS
Response:    227 Entering Passive Mode (192,3,170,172,132,153).
Command:    LIST
Error:    Connection timed out
Error:    Failed to retrieve directory listing


简单排查原因,发现FTP 21端口也打开了的,防火墙也打开对TCP 21端口的访问,登录权限也是配置好了的。
后来,将iptables防火前关闭后,就可以正常了使用了。
但是,为什么呢?

在服务器端用 watch netstat -tnl 命令查看网络连接情况,然后用FileZilla去连接FTP,会看到某个时刻(其实是发送了PASV命令后),服务器端会看到多了一个奇怪的IP端口连接,连接好后就消失了。
其实,这是FTP passive mode 和 active mode 的区别(不细说了看后面的参考资料吧),然后FileZilla默认使用的是passive mode(当然自己也可以去“设置”中更改)。

当然,我前面说将iptables关闭了,我也想重新把iptables重新启用,那么怎么设置访问哪个端口的规则呢?
当使用passive模式时,FTP服务器端会使用一个TCP端口,可通过下面的来配置:

 代码如下
pasv_enable=YES  # default YES. When enabled, passive mode connects are allowed.
pasv_min_port=9900
pasv_max_port=9903
port_enable=YES   # default NO. When enabled, active mode connects are allowed.


然后将9900、9901、9902、9903等4个端口的访问权限都在iptables中打开即可。

本文来源:http://www.bbyears.com/shoujikaifa/70850.html

热门标签

更多>>

本类排行