列表中的文件和远程Web的服务器文件夹(HTTP)文件夹、服务器、文件、列表中

2023-09-04 06:30:42 作者:Lie 说谎家

我想列出的文件在远程服务器(HTTP)。请咨询我关于一个控制台应用程序可能的选择。

I would like to list files on remote sever (HTTP). Please, advice me on possible options for a console application.

推荐答案

您可以使用的 Web客户端 类调用你的服务器,读取文件/目录列表和浏览目录递归。

You can use the WebClient class to call your server, read the file/directory lists and navigate through the directories recursively.

下面是基本使用Web客户端的:

Here is the basic use of WebClient:

WebClient client = new WebClient ();
Stream data = client.OpenRead ("http://example.com");
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd ();

// At this point, the variable s contains the returned webpage

另一种选择,其可以是更适合的,它以使用 HTML敏捷性包的 - 你可以使用 WebHtml 对象,直接从网络上获取的HTML,然后用它查询的XPath 的语法。

Another option, which may be more suitable, it to use the HTML Agility Pack - you can use the WebHtml object to retrieve HTML directly from the web and then query it using XPath syntax.