*/
private synchronized Socket createDataSocket() throws Exception {
// get socket depending on the selection
dataSoc = null;
DataConnectionConfiguration dataConfig = session.getListener()
.getDataConnectionConfiguration();
try {
if (!passive) {
int localPort = dataConfig.getActiveLocalPort();
if (secure) {
SslConfiguration ssl = dataConfig.getSslConfiguration();
if (ssl == null) {
throw new FtpException(
"Data connection SSL not configured");
}
if (localPort == 0) {
dataSoc = createSocket(ssl, address, port, null,
localPort, false);
} else {
InetAddress localAddr = resolveAddress(dataConfig
.getActiveLocalAddress());
dataSoc = createSocket(ssl, address, port, localAddr,
localPort, false);
}
} else {
if (localPort == 0) {
dataSoc = new Socket(address, port);
} else {
InetAddress localAddr =resolveAddress(dataConfig
.getActiveLocalAddress());
dataSoc = new Socket(address, port, localAddr,
localPort);
}
}
} else {
LOG.debug("Opening passive data connection");
dataSoc = servSoc.accept();
LOG.debug("Passive data connection opened");
}
} catch (Exception ex) {
closeDataConnection();
LOG.warn("FtpDataConnection.getDataSocket()", ex);
throw ex;
}
dataSoc.setSoTimeout(dataConfig.getIdleTime()*1000);
// Make sure we initate the SSL handshake, or we'll
// get an error if we turn out not to send any data
// e.g. during the listing of an empty dir
if (dataSoc instanceof SSLSocket) {
((SSLSocket) dataSoc).startHandshake();