use of org.apache.commons.net.ftp.FTPClient.NatServerResolverImpl in project fess-crawler by codelibs.
the class FtpClient method getClient.
protected FTPClient getClient(final FtpInfo info) throws IOException {
FTPClient ftpClient = ftpClientQueue.poll();
if (ftpClient != null) {
if (ftpClient.isAvailable()) {
return ftpClient;
}
try {
ftpClient.disconnect();
} catch (final Exception e) {
logger.debug("Failed to disconnect " + info.toUrl(), e);
}
}
try {
ftpClient = new FTPClient();
if (activeExternalHost != null) {
ftpClient.setActiveExternalIPAddress(activeExternalHost);
}
if (passiveLocalHost != null) {
ftpClient.setPassiveLocalIPAddress(passiveLocalHost);
}
if (reportActiveExternalHost != null) {
ftpClient.setReportActiveExternalIPAddress(reportActiveExternalHost);
}
if (activeMinPort != -1 && activeMaxPort != -1) {
ftpClient.setActivePortRange(activeMinPort, activeMaxPort);
}
ftpClient.setAutodetectUTF8(autodetectEncoding);
ftpClient.setConnectTimeout(connectTimeout);
ftpClient.setDataTimeout(dataTimeout);
ftpClient.setControlEncoding(controlEncoding);
ftpClient.setBufferSize(bufferSize);
if (passiveNatWorkaround) {
ftpClient.setPassiveNatWorkaroundStrategy(new NatServerResolverImpl(ftpClient));
}
ftpClient.setUseEPSVwithIPv4(useEPSVwithIPv4);
ftpClient.configure(ftpClientConfig);
ftpClient.connect(info.getHost(), info.getPort());
validateRequest(ftpClient);
final FtpAuthentication auth = ftpAuthenticationHolder.get(info.toUrl());
if (auth != null) {
if (!ftpClient.login(auth.getUsername(), auth.getPassword())) {
throw new CrawlerLoginFailureException("Login Failure: " + auth.getUsername() + " for " + info.toUrl());
}
}
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
return ftpClient;
} catch (final IOException e) {
if (ftpClient != null) {
try {
ftpClient.disconnect();
} catch (final Exception e1) {
logger.debug("Failed to disconnect " + info.toUrl(), e);
}
}
throw e;
}
}
Aggregations