FTP被动模式连接被拒绝(FTP passive mode connection refused)

Posted 格格巫 MMQ!!

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FTP被动模式连接被拒绝(FTP passive mode connection refused)相关的知识,希望对你有一定的参考价值。

我正在创建一个ftp客户端 ,我遇到了问题。
首先,我创建一个套接字,我发送USER和PASS然后PASV接收IP和PORT,然后创建第二个数据套接字并尝试连接,但是有一个问题。
它将连接5次6,但在第6次我收到错误111 Connection Refused ,我不知道如何解决这个问题。

I’m creating an ftp client and I have a problem.
First, I create a socket where I sent USER and PASS then PASV a receive IP and PORT and then create a second data socket and try to connect, but there is a problem.
It will connect 5 times of 6, but on the 6th time I got error 111 Connection Refused and I have no idea how to fix this.

PASV的响应文本没有标准格式(尽管EPSV确实如此),因此请确保正确解析IP /端口,因为您可能会收到真实服务器使用的许多不同格式之一:
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2
227 Entering Passive Mode. h1,h2,h3,h4,p1,p2
227 =h1,h2,h3,h4,p1,p2

只是为了展示一些可能性。
如果您正确解析IP /端口但仍然无法连接,则服务器上的IP /端口上的客户端连接太多,并且可用的插槽用完了,或者IP /端口正在连接被防火墙/路由器阻止,服务器不知道它何时向您报告IP /端口。
不幸的是, connection refused错误并没有提供任何区分这些条件的方法,因此您所能做的就是在传输失败之前尝试连接几次,或者发送ABOR以通知服务器关闭当前的被动IP /端口然后发送新的PASV以获得新的IP /端口。

The response text to PASV does not have a standardized format (EPSV does, though), so make sure you are parsing the IP/Port correctly, as you may receive one of many different formats used by real-world servers:
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2).
227 Entering Passive Mode (h1,h2,h3,h4,p1,p2
227 Entering Passive Mode. h1,h2,h3,h4,p1,p2
227 =h1,h2,h3,h4,p1,p2

Just to show a few possibilities.
If you are parsing the IP/Port correctly and still not able to connect, then either the server has too many client connections on the IP/Port and ran out of available slots for you to connect to, or else the IP/Port is being blocked by a firewall/router that the server does not know about when it reported the IP/Port to you.
Unfortunately, a connection refused error does not offer any way to differentiate between those conditions, so all you can do is attempt to connect a few times before failing the transfer, or else send an ABOR to inform the server to close the current passive IP/Port and then send a new PASV to get a new IP/Port.

以上是关于FTP被动模式连接被拒绝(FTP passive mode connection refused)的主要内容,如果未能解决你的问题,请参考以下文章

FTP Port主动模式 Passive被动模式区别-Filezilla Server设置Passive被动模式

ftp的passive模式

FTP的主动传输模式(PORT Mode)及被动传输模式(Passive Mode)(PASV)(FTP客户端 client 服务端 server 通信原理)

ftp的主动模式active mode和被动模式 passive mode的配置和区别

python ftp模块有支持passive off这个命令吗

大白话解释一下“被动FTP模式”是啥意思?