2013-01-13 115 views
4

我使用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(); 
     } 
    } 
+0

我剛剛發現應該在'retrieve | storeFileStream'的流關閉後調用'completePendingCommand'。 –

回答

2

我不認爲你做錯了什麼,我不認爲元數據提取器有什麼問題。您最好檢查正在檢索的流是否可以正確處理,而不是使用completePendingCommand()作爲成功的指示。如果出現問題,元數據提取器可能已經通過拋出異常來爲您執行此操作。

說明: completePendingCommand()驗證整個事務和成功或失敗的成功依賴於FTPClients 200 < = replyCode < 300(http://commons.apache.org/proper/commons-net/apidocs/src-html/org/apache/commons/net/ftp/FTPReply.html#line.133)的範圍內回覆代碼之中。

我有一個類似的問題,並發現我的FTPClient對象的回覆代碼爲150,表明根據FTP服務器,事務尚未完成。答覆代碼150是肯定的初步答覆,但未被歸類爲答覆完成答覆(http://tools.ietf.org/html/rfc959,第37頁)。我的觀點是,答覆仍然是積極的,儘管我認爲我已經完成了交易,但FTP服務器仍然認爲我需要做些事情。這可能是org.apache.commons.net.ftp.FTPClient或與之交互的FTP服務器的問題。

相關問題