1

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.

sgress454
  • 24,870
  • 4
  • 74
  • 92
Petr Skyva
  • 71
  • 2
  • 5

1 Answers1

1

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.

Community
  • 1
  • 1
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770