2011-01-10 79 views
0

我無法使用FTPClient獲取確切的文件列表。如以下示例代碼:FTP客戶端 - 列表文件

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 ..

謝謝

+0

您需要對問題進行更具描述性的描述。當你運行代碼時會發生什麼?你能登錄嗎?你有一些數據嗎?不是嗎? – 2011-01-10 09:33:09

+0

請解釋一下,你*期望什麼*以及你目前*觀察到什麼*(iaw - 你的結果列表中缺少什麼) – 2011-01-10 09:33:10

回答

2

我不知道什麼是files,但你得到的client.listFiles的結果ftpFiles,而不是在files。然後在您的for循環中,您可以通過files

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

這應該有效。
謝謝。