FTP客户端 - 列表文件

问题描述:

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

我不知道什么是files,但你得到的client.listFiles的结果ftpFiles,而不是在files。然后在您的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); 
    }  
} 

这应该有效。
谢谢。