FTP 客户端 - 列表文件

发布于 2024-10-11 02:17:09 字数 536 浏览 12 评论 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 ..

谢谢

I am unable to get the exact file list using FTPClient. Sample code as below :

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

I tried to set to PASV mode using enterLocalPassiveMode()/enterRemotePassiveMode()/pasv(). But, it doesnt work.

Please also check Apache Commons FTPClient.listFiles ..

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愛放△進行李 2024-10-18 02:17:09

我不知道 files 是什么,但您在 ftpFiles 中获得 client.listFiles 的结果,而不是在 中文件。然后在 for 循环中遍历文件

I don't know what files is, but you're getting the results of client.listFiles in ftpFiles, and not in files. Then in your for loop you go over files.

牛↙奶布丁 2024-10-18 02:17:09

试试这个。

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

这应该有效。
谢谢。

Try this.

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

This should work.
Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文