0

FTPClient を使用して正確なファイル リストを取得できません。以下のサンプルコード:

FTPClient client = new FTPClient();
client.connect("x.x.x.x");
client.login("abcd", "abcd");
FTPFile[] ftpFiles = client.listFiles();
for (FTPFile ftpFile : ftpFiles) {
   System.out.println("FTPFile: " + ftpFile.getName());
}

enterLocalPassiveMode()/enterRemotePassiveMode()/pasv() を使用して PASV モードに設定しようとしました。しかし、それはうまくいきません。

Apache Commons FTPClient.listFilesも確認してください。

ありがとうございました

4

2 に答える 2

2

が何であるかはわかりませんが、 inではなく infilesの結果が得られます。次に、ループで.client.listFilesftpFilesfilesforfiles

于 2011-01-10T09:34:24.510 に答える
1


これを試して。

String[] fileFtp = client.listNames();//if it is directory. then list of file names

//download file
for (int i =0;i<fileFtp.length;i++) {

   String fileName = fileFtp[i];

   OutputStream out = new FileOutputStream(new File("local temp file name"));

   if (!client.retrieveFile(fileName, out)) {       
        sysout("Could not download the file. "+ fileName);
    } else {
        sysout("Downloaded file @ : "+localFileName);   
    }       
} 

これはうまくいくはずです。
ありがとう。

于 2011-01-10T09:39:52.620 に答える