protected void _parsePassiveModeReply(String reply)
throws MalformedServerReplyException
{
java.util.regex.Matcher m = __PARMS_PAT.matcher(reply);
if (!m.find()) {
throw new MalformedServerReplyException(
"Could not parse passive host information.\nServer Reply: " + reply);
}
__passiveHost = m.group(1).replace(',', '.'); // Fix up to look like IP address
try
{
int oct1 = Integer.parseInt(m.group(2));
int oct2 = Integer.parseInt(m.group(3));
__passivePort = (oct1 << 8) | oct2;
}
catch (NumberFormatException e)
{
throw new MalformedServerReplyException(
"Could not parse passive port information.\nServer Reply: " + reply);
}
try {
InetAddress host = InetAddress.getByName(__passiveHost);
// reply is a local address, but target is not - assume NAT box changed the PASV reply
if (host.isSiteLocalAddress() && !getRemoteAddress().isSiteLocalAddress()){
String hostAddress = getRemoteAddress().getHostAddress();
fireReplyReceived(0,
"[Replacing site local address "+__passiveHost+" with "+hostAddress+"]\n");
__passiveHost = hostAddress;
}
} catch (UnknownHostException e) { // Should not happen as we are passing in an IP address
throw new MalformedServerReplyException(
"Could not parse passive host information.\nServer Reply: " + reply);
}
}