复制 Web 目录和文件以进行更新?
Copy a web directory and files for updates?
直接来自 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
但来自网络目录
当我搜索你的案例时,你可能会使用 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();
直接来自 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
但来自网络目录
当我搜索你的案例时,你可能会使用 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();