session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.disabled", null));
return;
}
InetSocketAddress address;
try {
address = SocketAddressEncoder.decode(request.getArgument());
// port must not be 0
if(address.getPort() == 0) {
throw new IllegalPortException("PORT port must not be 0");
}
} catch (IllegalInetAddressException e) {
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT", null));
return;
} catch (IllegalPortException e) {
LOG.debug("Invalid data port: " + request.getArgument(), e);
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.invalid", null));
return;
} catch (UnknownHostException e) {
LOG.debug("Unknown host", e);
session
.write(LocalizedFtpReply
.translate(
session,
request,
context,
FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS,
"PORT.host", null));
return;
}
// check IP
if (dataCfg.isActiveIpCheck()) {
if (session.getRemoteAddress() instanceof InetSocketAddress) {
InetAddress clientAddr = ((InetSocketAddress) session
.getRemoteAddress()).getAddress();
if (!address.getAddress().equals(clientAddr)) {
session.write(LocalizedFtpReply.translate(session, request,
context, FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "PORT.mismatch", null));
return;
}
}