【问题标题】:Copy a web directory and files for updates?复制 Web 目录和文件以进行更新?
【发布时间】:2016-03-14 06:12:17
【问题描述】:

直接来自 MSDN 教程:

string remoteUri = "http://www.contoso.com/library/homepage/images/";
string fileName = "ms-banner.gif", myStringWebResource = null;

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);

// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);     
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);

有没有一种简单的方法可以下载文件夹及其子文件夹及其文件?我知道如何使用 dos 来执行此操作,但是您如何在 C# 中执行此操作?一定有一个简单的公式。

using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://www.website.com/tools/update/*.*", @"c:\downloads");

有点喜欢做:

xcopy source destination /E 

但来自网络目录

【问题讨论】:

    标签: c# web directory copy


    【解决方案1】:

    当我对您的案例进行搜索时,您可能的选择是使用WGET 命令行工具。您可以从here 获得它。

    使用this 引用递归下载。

    使用 WGET 的示例;

       ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe");
       Process p = new Process();
       startInfo.RedirectStandardInput = true;
       startInfo.UseShellExecute = false;
       startInfo.RedirectStandardOutput = true;
       startInfo.RedirectStandardError = true;
       p = Process.Start(startInfo);
       p.StandardInput.WriteLine(@"wget -r http://www.website.com/tools/update");
    
       p.StandardInput.WriteLine(@"EXIT");
       string output = p.StandardOutput.ReadToEnd();
       string error = p.StandardError.ReadToEnd();
       p.WaitForExit();
       p.Close();
    

    【讨论】:

    • 谢谢。只是想弄清楚它在哪里下载文件,或者我是否可以将它定向到 C:\downloads
    猜你喜欢
    • 2019-04-03
    • 2019-11-01
    • 2015-02-03
    • 2012-03-18
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    相关资源
    最近更新 更多