简体   繁体   English

使用Java从远程URL列出文件

[英]Listing files from a remote URL using Java

I would like to list the files in a certain URL that requires authentication. 我想在需要身份验证的特定URL中列出文件。 Note that I have no access to the FTP server. 请注意,我无权访问FTP服务器。 Is there any possible way that I can do this using Java? 有什么办法可以使用Java做到这一点?

Accessing FTP from java is at best an arduous task, because the standard library doesn't provide anything for it. 从Java访问FTP充其量是一项艰巨的任务,因为标准库没有为此提供任何服务。 However, there are a few ways. 但是,有几种方法。 There are three way to read directory listings, explained on nsftools : 有三种读取目录列表的方法,在nsftools上进行了解释

  • Write your own class to talk to the FTP server. 编写自己的类与FTP服务器对话。 This is very compicated, and there are already such classes. 这非常复杂,并且已经有此类。
  • Use the sun.net.ftp.FTPClient class. 使用sun.net.ftp.FTPClient类。 This class is used internally by the java library to download files from FTP, but it is undocumented, not guaranteed to be present in all java implementations, &c. java库在内部使用该类从FTP下载文件,但未记录该文件,不能保证在所有java实现中都存在&c。 Plus, directory listings are very hard to parse. 另外,目录列表很难解析。
  • Use the Jarkarta Net FTP library. 使用Jarkarta Net FTP库。 This I think is the best option, but it has only one disadvantage: You need to supply the jar file as a dependency. 我认为这是最好的选择,但它只有一个缺点:您需要提供jar文件作为依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM