我在 Websphere 上有一个 java 应用程序,它使用 Apache Commons FTPClient 通过 FTP 从 Windows 服务器检索文件。当我将应用程序部署到在 Windows 环境中运行的 Websphere 时,我能够干净地检索所有文件。但是,当我在 Linux 上将相同的应用程序部署到 Webpshere 时,有时会收到不完整或损坏的文件。但是这些情况是一致的,因此相同的文件每次都会失败并返回相同数量的字节(通常只比我应该得到的少几个字节)。我想说我可以在 Linux 上成功读取大约 95% 的文件。
这是相关的代码...
ftpc = new FTPClient();
// set the timeout to 30 seconds
ftpc.enterLocalPassiveMode();
ftpc.setDefaultTimeout(30000);
ftpc.setDataTimeout(30000);
try
{
String ftpServer = CoreApplication.getProperty("ftp.server");
String ftpUserID = CoreApplication.getProperty("ftp.userid");
String ftpPassword = CoreApplication.getProperty("ftp.password");
log.debug("attempting to connect to ftp server = "+ftpServer);
log.debug("credentials = "+ftpUserID+"/"+ftpPassword);
ftpc.connect(ftpServer);
boolean login = ftpc.login(ftpUserID, ftpPassword);
if (login)
{
log.debug("Login success..."); }
else
{
log.error("Login failed - connecting to FTP server = "+ftpServer+", with credentials "+ftpUserID+"/"+ftpPassword);
throw new Exception("Login failed - connecting to FTP server = "+ftpServer+", with credentials "+ftpUserID+"/"+ftpPassword);
}
is = ftpc.retrieveFileStream(fileName);
ByteArrayOutputStream out = null;
try {
out = new ByteArrayOutputStream();
IOUtils.copy(is, out);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(out);
}
byte[] bytes = out.toByteArray();
log.info("got bytes from input stream - byte[] size is "+ bytes.length);
对此的任何帮助将不胜感激。
谢谢。