// get the passive port
int passivePort = session.getListener()
.getDataConnectionConfiguration().requestPassivePort();
if (passivePort == -1) {
servSoc = null;
throw new DataConnectionException(
"Cannot find an available passive port.");
}
// open passive server socket and get parameters
try {
DataConnectionConfiguration dataCfg = session.getListener()
.getDataConnectionConfiguration();
String passiveAddress=dataCfg.getPassiveAddress();
if (passiveAddress == null) {
address = serverControlAddress;
}else{
address = resolveAddress(dataCfg.getPassiveAddress());
}
if (secure) {
LOG
.debug(
"Opening SSL passive data connection on address \"{}\" and port {}",
address, passivePort);
SslConfiguration ssl = dataCfg.getSslConfiguration();
if (ssl == null) {
throw new DataConnectionException(
"Data connection SSL required but not configured.");
}
servSoc = createServerSocket(ssl, address, passivePort);
port = servSoc.getLocalPort();
LOG
.debug(
"SSL Passive data connection created on address \"{}\" and port {}",
address, passivePort);
} else {
LOG
.debug(
"Opening passive data connection on address \"{}\" and port {}",
address, passivePort);
servSoc = new ServerSocket(passivePort, 0, address);
port = servSoc.getLocalPort();
LOG
.debug(
"Passive data connection created on address \"{}\" and port {}",
address, passivePort);
}
servSoc.setSoTimeout(dataCfg.getIdleTime() * 1000);
// set different state variables
passive = true;
requestTime = System.currentTimeMillis();
return new InetSocketAddress(address, port);
} catch (Exception ex) {
servSoc = null;
closeDataConnection();
throw new DataConnectionException(
"Failed to initate passive data connection: "
+ ex.getMessage(), ex);
}
}