• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

Directory listing over HTTP

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
Jeex
Asked:
Jeex
  • 5
  • 4
  • 2
  • +2
1 Solution
 
TimYatesCommented:
>> 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
 
bloodredsunCommented:
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
 
bloodredsunCommented:
Then use lastModified() and .length() to get the alst modified and size of the files.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
bloodredsunCommented:
oh and isFile() or isDirectory() to find out whether the files are one or the other.
0
 
TimYatesCommented:
>>  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
 
bloodredsunCommented:
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
 
JeexAuthor Commented:
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
 
rrzCommented:
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
 
TimYatesCommented:
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
 
rrzCommented:
>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
 
aprasadhCommented:
do you want to use the http protocol to connect to other machine (webserver) or you have any other facility?
0
 
JeexAuthor Commented:
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
 
TimYatesCommented:
points for me I reckon...as my first comment says, there is no built in/generic way of doing this...
0
 
bloodredsunCommented:
Yep, points for Mr TimYates
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now