user1144
user1144

Reputation:

C# .NET listing contents of remote files

Is it possible in .NET to list files on a remote location like an URL? Much in the same way the System.IO classes work. All I need is the URLs to images that are on a remote server.

Upvotes: 4

Views: 2241

Answers (2)

Sören Kuklau
Sören Kuklau

Reputation: 19930

Is it possible in .NET to list files on a remote location like an URL?

You should specify which protocol we're talking about.

For HTTP, lubos hasko provided the answer: no. HTTP has no concept of files; only of resources. If you have control over the web server, you can ask it to provide a directory listing, or, better yet, you can write code that lists the directory server-side for you. Without such control, you have to rely on the server to provide a listing, which 1) may be disabled for security reasons, 2) is non-standardized in its format, 3) will be, like lubos said, fragile to parse ("scrape").

If you mean / if the server provides a protocol intended for file transfer, such as FTP, SMB/CIFS, etc., it'll be a lot easier. For example, for FTP, you'll want to look into WebRequestMethods.Ftp.ListDirectoryDetails.

Upvotes: 1

lubos hasko
lubos hasko

Reputation: 25052

Short answer: No, unless you have more control over that web-server

Long answer: Here are possible solutions...

  1. You will need server-side script that will do it locally and output this list in your preferred format.

  2. Most of the web-servers implement default file-browsing pages, so you could theoretically parse those but this solution will be very fragile and not very portable even between different versions of the same web-server.

  3. If you have FTP access...

Upvotes: 3

Related Questions