Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Code that list links for the site, is it possible to view directory contents for the directory say for instance list files at location http://www.youtube.com/Songs

package Jsoup;

import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class LinkParser {

    public static void main(String[] args) throws IOException {
        
        String url = "http://www.youtube.com";

        Document document = Jsoup.connect(url).get();
        Elements links = document.select("a[href]");
        
        for (Element link : links) {
            
            System.out.println("link : " + link.attr("href"));
            System.out.println("text : " + link.text());
        }
    }
}



The code that displays directory content from computer but not from remote machine via hyper text transfer protocol, http

package Io;

import java.io.File; 

public class Directories {
    
}
 
class DirList { 
  public static void main(String args[]) { 
    String dirname = "/Games"; 
    File f1 = new File(dirname); 
 
    if (f1.isDirectory()) { 
      System.out.println("Directory of " + dirname); 
      String s[] = f1.list(); 
 
      for (int i=0; i < s.length; i++) { 
        File f = new File(dirname + "/" + s[i]); 
        if (f.isDirectory()) { 
          System.out.println(s[i] + " is a directory"); 
        } else { 
          System.out.println(s[i] + " is a file"); 
        } 
      } 
    } else { 
      System.out.println(dirname + " is not a directory"); 
    } 
  } 
}


What I have tried:

changed the url , ran the code for several sites still doesnt display directory contents. There is a similar application with java but it displays directory contents from the computer and not from remote machine via http:
Posted
Updated 16-Jan-18 3:41am
Comments
Richard MacCutchan 16-Jan-18 9:11am    
Most websites do not allow you to do that; for very good reasons.
José Amílcar Casimiro 16-Jan-18 9:30am    
You have to read some information about web server security templates. However, if you insist on continuing on this path, try searching in google "intitle: Index of" and you'll find sites that work with the code you want.
four systems 17-Jan-18 7:32am    
cool

1 solution

The URL must have a trailing slash to retrieve directory listings (e.g. http://www.example.com/sub/). Without the trailing slash you will get the default page for that directory. For the main directory that is usually the start page and for sub directories it might be a default page or an error depending on the web server configuration.

But the generation of directory listings must be configured on the web server and is usually disabled resulting in an error response.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900