<p>I need a short code snippet to get a directory listing from an HTTP server.</p>

<p>Thanks</p>

Basic understanding:
Directory listings are just HTML pages generated by a web server.
Each web server generates these HTML pages in its own way because there is no standard way for a web server to list these directories.
The best way to get a directory listing, is to simply do an HTTP request to the URL you'd like the directory listing for and to try to parse and extract all of the links from the HTML returned to you.
To parse the HTML links please try to use the
HTML Agility Pack
.
Directory Browsing:
The web server you'd like to list directories from must have directory browsing turned on to get this HTML representation of the files in its directories.  So you can only get the directory listing if the HTTP server wants you to be able to.
A quick example of the HTML Agility Pack:
```
```
HtmlDocument doc = new HtmlDocument();
doc.Load(strURL);
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a@href")
{
HtmlAttribute att = link"href";
//do something with att.Value;
}
```
```
Cleaner alternative:
If it is possible in your situation, a cleaner method is to use an intended protocol for directory listings, like the File Transfer Protocol (FTP), SFTP (FTP like over SSH) or FTPS (FTP over SSL).
What if directory browsing is not turned on:
If the web server does not have directory browsing turned on, then there is no easy way to get the directory listing.
The best you could do in this case is to start at a given URL, follow all HTML links on the same page, and try to build a virtual listing of directories yourself based on the relative paths of the resources on these HTML pages.  This will not give you a complete listing of what files are actually on the web server though.