簡體   English   中英

FTP客戶端-列表文件

[英]FTP client - listfiles

我無法使用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 ..

謝謝

我不知道files是什么,但是您在ftpFiles中而不是files獲得client.listFiles的結果。 然后在for循環中遍歷files


嘗試這個。

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);   
    }       
} 

這應該工作。
謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM