FTPClient ftpClient = new FTPClient();
FileInputStream fileInputStream;
try {
ftpClient.connect(HOST);
ftpClient.login(USER_NAME, PASSWORD);
ftpClient.enterLocalPassiveMode();
fileInputStream = new FileInputStream(reconciliationFile);
Boolean isSuccess = ftpClient.storeFile("/" + PATH + "/" + reconciliationFile.getName(), fileInputStream);
logger.info("上传取暖对账文件结果:{}",isSuccess.toString());
reconciliationFile.deleteOnExit();
return true;
} catch (IOException e) {
logger.info(e.getMessage(), e);
throw new RuntimeException("FTP客户端出错!", e);
}
}
如果没有
ftpClient.enterLocalPassiveMode();
将会抛出异常java.net.socketexception: connection timed out
或者isSuccess的将为false;