2010-12-15 8 views
7

私はFTPサーバーから取得するためにapache-commons net FTP libを使用しようとしています。ディレクトリ内に1つのファイルしかない場合でもコードはうまく動作しますが、2回目にretrieveFileStream()を呼び出すと常にnullが返されます。何かご意見は?私は私の問題を示すために、次のコード例を書いた。apache-commons ftp複数のファイルを取得する

public static void main(String[] args) throws Exception 
    { 
    String strLine; 
    FTPClient client = null; 

    try{ 
     client = new FTPClient(); 
     client.connect("localhost", 21); 
     client.enterLocalPassiveMode(); 
     client.login("ftptester", "letmein"); 

     client.changeWorkingDirectory("remote"); 

     FTPFile[] ftpFiles = client.listFiles();   
     if (ftpFiles != null && ftpFiles.length > 0) { 
     for (FTPFile file : ftpFiles) { 
      if (!file.isFile()) { 
      continue; 
      } 

      InputStream fin = client.retrieveFileStream(filepath); 
      if (fin == null) { 
      System.out.println("could not retrieve file: " + filepath); 
      continue; 
      } 

      byte[] data = readBytes(fin); // helper method not shown, just processes the input stream 
      fin.close(); 
      fin = null; 

      System.out.println("data: " + new String(data));   
     } 
     } 
    } 
    finally { 
     ... // cleanup code 
    } 
    } 

答えて

17

Doh!不足している魔法は:

completePendingCommand() 
+0

ありがとう!それは実際に私の問題で私を助けた – Ascalonian

+0

同じ、ありがとう! – Gevorg

+0

私はちょうどこの1つを理解しようとしている最後の時間だった - ありがとう! – kbbucks

関連する問題