8

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

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
    }
  }
4

1 に答える 1

17

どっ!不足している魔法は次のとおりです。

completePendingCommand()
于 2010-12-15T18:23:09.670 に答える