我正在使用 apache commons net 库从 FTP 服务器获取文件。
我不需要下载整个文件,只需读取标题以确定文件大小。我用来执行此操作的库是元数据提取器
问题是当我调用client.completePendingCommand()它总是返回 false - 但是日期变量打印正确。我问过元数据提取器的开发人员,他不知道为什么它返回错误。有人有解释吗?我不确定是否可以忽略错误?
FTPClient client = new FTPHTTPClient(proxy settings);
InputStream stream = null;
try {
client.connect(FTPProperties.getInstance().getProperty("ftp.server"));
client.login(FTPProperties.getInstance().getProperty("ftp.username"), FTPProperties.getInstance().getProperty("ftp.password"));
client.enterLocalPassiveMode();
for (String path : paths) { //paths are the jpeg files to download
try {
stream = client.retrieveFileStream(p);
Metadata metadata = ImageMetadataReader.readMetadata(stream);
Directory directory = metadata.getDirectory(ExifSubIFDDirectory.class);
Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
System.out.println("DATE " + date);
} catch (IOException ex) {
Logger.getLogger(UploadImage.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if(stream != null) {
stream.close();
}
if (in != null) {
in.close();
}
if (!client.completePendingCommand()) {
Logger.getLogger("Error");
}
}
}
} catch (Exception ex) {
Logger.getLogger(UploadImage.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (client != null && client.isConnected()) {
client.disconnect();
}
}