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.