从Java客户端应用程序枚举目录/文件的HTTP服务器上 [英] enumerating directories/files on an HTTP server from a Java client application

查看:129
本文介绍了从Java客户端应用程序枚举目录/文件的HTTP服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要写一个Java客户端应用程序当中,给下面的网址时,会枚举递归下它的目录/文件。我还需要获得最后修改的时间戳每个因为我只关心,因为已知时间戳的变化。

I need to write a Java client application which, when given the below URL, will enumerate the directories/files recursively beneath it. I also need to get the last modified timestamp for each since I'm only concerned with changes since a known timestamp.

http://www.myserver.com/testproduct/

例如,假设下面存在于服务器上。

For example, suppose the following exist on the server.

http://www.myserver.com/testproduct/red/file1.txt
http://www.myserver.com/testproduct/red/file2.txt
http://www.myserver.com/testproduct/red/black/file3.txt
http://www.myserver.com/testproduct/red/black/file4.txt
http://www.myserver.com/testproduct/orange/anotherfile.html
http://www.myserver.com/testproduct/orange/mymovie.avi
http://www.myserver.com/testproduct/readme.txt

我需要,开始在指定的URL(http://www.myserver.com/testproduct/)列举的目录和文件递归它下面的每个上次修改的时间戳。一旦我的目录/文件列表中,我会选择下载基于时间戳和其他客户端过滤器的一些文件。

I need to, starting at the specified URL (http://www.myserver.com/testproduct/) enumerate the directories and files recursively beneath it along with the last modified timestamp of each. Once I have the list of directories/files, I'll be selectively downloading some of the files based on timestamp and other client-side filters.

服务器正在运行Apache和被配置为允许目录列表。

The server is running Apache and is configured to allow directory listing.

我没有使用Apache的HttpClient的Java类进行一些试验,当我请求 HTTP://www.myserver .COM / testproduct / 我回去一个HTML文件,这当然是你看到,如果你在你的浏览器去那里同样的事情。其一个HTML页面表示该文件夹的内容。

I did some experimentation using Apache's HttpClient Java class and when I request the contents of http://www.myserver.com/testproduct/ I get back an HTML file which of course is the same thing you see if you go there in your browser. Its an HTML page showing the contents of the folder.

这是做到这一点的唯一途径?即刮生成的HTML页面解析出的文件和目录?另外,我不知道从目录基于HTML我可以可靠地分辨文件返回

Is this the only way to do it? i.e. scraping the resulting HTML page to parse out the files and directories? Also, I'm not sure I can reliably distinguish files from directories based on the HTML returned

有没有更好的办法来枚举目录和文件,而无需页面刮结果HTML?

Is there a better way to enumerate directories and files without page scraping the resultant HTML?

推荐答案

如果您对服务器的控制,你应该问他们实施的的WebDAV ,这是为precisely那种情景。阿帕奇配备了一个的mod_dav ,只是需要进行配置。在Java客户端,请参见

If you have any control over the server, you should ask them to implement WebDAV, which is meant for precisely that sort of scenario. Apache comes with a mod_dav that just needs to be configured. On the Java client side, see this question

这篇关于从Java客户端应用程序枚举目录/文件的HTTP服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆