我使用apache commons net library從FTP服務器獲取文件。apache commons net - completepending命令返回false
我不需要下載整個文件,只需要讀取標題以確定文件大小。我使用做這個圖書館是metadata extractor
的問題是,當我叫client.completePendingCommand()它始終返回false - 但日期變量打印正確。我問過元數據提取的開發者,他不知道爲什麼它返回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();
}
}
我剛剛發現應該在'retrieve | storeFileStream'的流關閉後調用'completePendingCommand'。 –