ServerDataConnectionFactory dataCon = session.getDataConnection();
String externalPassiveAddress = getPassiveExternalAddress(session);
try {
InetSocketAddress dataConAddress = dataCon.initPassiveDataConnection();
// get connection info
InetAddress servAddr;
if (externalPassiveAddress != null) {
servAddr = resolveAddress(externalPassiveAddress);
} else {
servAddr = dataConAddress.getAddress();
}
// send connection info to client
InetSocketAddress externalDataConAddress = new InetSocketAddress(
servAddr, dataConAddress.getPort());
String addrStr = SocketAddressEncoder.encode(externalDataConAddress);
session.write(LocalizedFtpReply.translate(session, request, context,
FtpReply.REPLY_227_ENTERING_PASSIVE_MODE, "PASV", addrStr));