?
Solved

Directory listing over HTTP

Posted on 2005-03-15
15
Medium Priority
?
169 Views
Last Modified: 2008-01-09
From my Servlet or JSP, I'd like to be able to get a list of all the files and/or directories in a directory using the HTTP directory listing feature.

For example:
- my JSP is on: http://www.mycompany.com/getlist.jsp
- the directory I want to list the contents of is at: http://www.othercompany.com/files/

The resulting output I'd like from my JSP should be something like:
-----
Hello, there are 2 files and 1 directories in the /files/ directory!
The files are:
- bigfile.zip is 350 MB and was last modified on 15 March 2005 at 11:38:29
- smallpdf.pdf is 24 KB  and was last modified on 2 April 2004 at 09:23:14
The directories are:
- /morefiles/
-----

Is there any clever/built-in way of doing this with Java, aside from creating a function that parses the HTML returned from the web server's HTTP directory listing?

Cheers,

-- James
0
Comment
Question by:Jeex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
15 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13543181
>> Is there any clever/built-in way of doing this with Java, aside from creating a function that parses the HTML returned from the web server's HTTP directory listing?

No :-(
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13543291
What about somhting like this converted to output in servlet or jsp?

package com.bloodredsun;

import java.io.File;
import java.util.Arrays;

public class Ls {

      public static void main( String[] args){
            
            String[] dir = new File("src/com/bloodredsun").list() ;
            Arrays.sort(dir);
            for (int ii = 0 ; ii < dir.length ; ii++){
                  System.out.println(dir[ii]);
            }
      }
}
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13543301
Then use lastModified() and .length() to get the alst modified and size of the files.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:bloodredsun
ID: 13543306
oh and isFile() or isDirectory() to find out whether the files are one or the other.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13543309
>>  What about somhting like this converted to output in servlet or jsp?

I think he wants a directory listing off a different remote machine

ie:

   user -> webserver -> webserver
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13543411
Doh! Don't I feel stupid for not reading the question completely.

Jeex, TimYates is correct in his first post when he says no (I thought it was on your own machine). Unforrtunately, my posts are fairly useless for someone in your position!
0
 
LVL 3

Author Comment

by:Jeex
ID: 13544544
Right, thanks anyway... I'll leave this open for a while longer in case someone does come up with a never-before-heard-of solution (or library...).
0
 
LVL 28

Expert Comment

by:rrz
ID: 13545034
Here is a similar question(with answers). My post uses recursion  to list all files and directories.
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21288636.html
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13545070
you've made the same mistake bloodredsun has...

he wants a directory listing off of another remote machine, not the machine that this webserver is running on....another one...
0
 
LVL 28

Expert Comment

by:rrz
ID: 13545599
>you've made the same mistake bloodredsun has...    
Well then I am in good company. Thanks Tim.   But, does Jeex want to list files in sub-directorties ?  
0
 
LVL 1

Expert Comment

by:aprasadh
ID: 13546366
do you want to use the http protocol to connect to other machine (webserver) or you have any other facility?
0
 
LVL 3

Author Comment

by:Jeex
ID: 13556210
All I have access to is the default Apache directory listing you see when you go to a web-site sub-directory with no index page defined (and which allows directory listing).

From that content, I need to be able to create a list of the files and directories at that level and all sub-levels, and store that list as an XML document.

Currently, I've written some code which parses the HTML contents of the directory listing, and extracts the necessary data - recursively for all directories. This isn't ideal because the format of the HTML may change, for example when the web server is updated.

So I was wondering if there was some better more generic way of doing what I need to do... Hopefully that's clear? o_O

Cheers,

-- James
0
 
LVL 35

Accepted Solution

by:
TimYates earned 2000 total points
ID: 13731687
points for me I reckon...as my first comment says, there is no built in/generic way of doing this...
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13731854
Yep, points for Mr TimYates
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
The top devops trends for 2017 are focused on improved deployment frequency, decreased lead time for change and decreased MTTR.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question