在Java中通过HTTP下载目录 [英] Download a directory over HTTP in Java

查看:163
本文介绍了在Java中通过HTTP下载目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录树中有一些文件通过HTTP提供。
给定一些子目录A,在该目录树中,我想要能够下载目录A和所有包含子目录和文件。



Java的一些黑暗角落似乎有一个简单/直接/原子解决方案。有没有人知道如何做?



网络抓取工具不会解决我的问题,因为子目录中的文件可能链接到不是子目录的目录。



==更新==



目录和文件必须以静态方式托管。

服务器在目录树中静态托管文件,客户端正在运行Java,并尝试使用HTTP复制目录树的某些分支。



VFS 是答案,不幸的是我回答了这个问题我等到现在两天以后就不能选择答案了。如果有人写我的答案,我很乐意把他们的写作作为答案。



==进一步的更新==



VFS 其实不是回答。 VFS不会通过HTTP列出目录,如这里所述。似乎有几个人对该功能感兴趣。

解决方案

假设您有权控制服务器和客户端,我将编写一个页面(您最喜欢的技术选择; ASP,JSP,PHP等),它读取服务器目录结构,并动态地返回一个页面,其中包含一堆到每个文件的链接请下载。



然后客户端可以触发每个链接的下载。



客户端是什么技术?是下载某种应用程序或网络浏览器的事情吗?它是否必须有一个客户端界面?






如果这是某种内部的实用程序,也许你可以只是FTP?在服务器上打开FTP访问并下载目录将很容易...






添加另一个可能的答案:



如果服务器没有打开目录列表,那么您基本上必须修改服务器端。最简单的事情就是让一个页面以已知的格式返回给客户端的dir结构(见上面我的第一个答案)。



如果你控制服务器并且在上有目录列表,您始终使用相同的服务器程序(IIS,Tomcat,JBoss等),那么您可能只能使客户端Webcrawl目录列表。例如,在IIS的目录中,您可以确定哪些链接是目录,哪些是文件,因为它始终在目录链接的末尾放置一个/,并显示dir而不是文件大小: p>

  2009年10月16日(星期五)03:55 PM& lt&dir& < A href =Unity /> Unity< / A> 
2009年7月2日,星期四上午10:42 95< A href =Global.asax> Global.asax< / A>

你可以告诉这里,第一个链接是一个目录,第二个是一个实际的文件。 / p>

因此,如果您使用一致的服务器应用程序,请查看目录列表的返回方式。也许你会幸运的。


I have some files in a directory tree which is being served over HTTP. Given some sub-directory A, in that directory tree I want to be able to download directory A and all containing subdirectories and files.

It seems likely that a simple/direct/atomic solution exists in the some dark corner of Java. Does anyone know how to do this?

A webcrawler will not solve my problem since files in sub-directories may link to directories that are not subdirectories.

==Update==

The directories and files must be hosted in static manner.

The server is statically hosting files in a directory tree, the client is running Java and attempting to copy some branch of the directory tree using HTTP.

VFS is the answer to this, unfortunately I answered the question myself and so can't choose it as the answer until two days from now. If someone would write up of my answer I would be happy to mark their write up as the answer.

==Further Update==

VFS is in fact not the answer. VFS will not list directories over HTTP, as stated here. There does seem to be a few people that are interested in that functionality.

解决方案

Assuming you have control over both the server and client, I would write a page (in your favorite technology of your choice; ASP, JSP, PHP, etc) that reads the server directory structure, and dynamically returns a page that consists of a bunch of links to each file to be downloaded.

Then client side you can trigger a download of each link.

What is the client side technology? is the thing doing the downloading an application of some sort, or a web browser? Does it have to have a client interface?


If this is some sort of in-house utility program, maybe you can just FTP instead? Having FTP access open on a server and downloading a directory would be easy...


Adding another possible answer:

If the server does not have directory listings turned on, then you basically have to make a modification server side. The easiest thing would be to just make a page that returns the dir structure to the client in a known format (see my 1st answer above).

If you control the server and have directory listings on, and you are always using the same server program (IIS, Tomcat, JBoss, etc) then you might be able to just make the client webcrawl the directory listings. For example, in a directory listing from IIS, you can tell which links are directories and which are files because it always puts a '/' at the end of a directory link, and shows 'dir' instead of a file size:

 Friday, October 16, 2009 03:55 PM        &lt;dir&gt; <A href="Unity/">Unity</A>
 Thursday, July 02, 2009 10:42 AM           95 <A href="Global.asax">Global.asax</A>

You can tell here that the 1st link is a directory, and the 2nd is an actual file.

So if you are using a consistent server app, just take a look at how the directory listing is returned. Maybe you'll get lucky.

这篇关于在Java中通过HTTP下载目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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