1

Straight from MSDN tutorials:

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);

Is there a simple way to download a folder and it's subfolders with their files? I know how to use dos to do this, but how do you do this in C#? There must be a simple formula.

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

kind of like doing:

xcopy source destination /E 

but from a web directory

Irshad
  • 3,071
  • 5
  • 30
  • 51
DDJ
  • 807
  • 5
  • 13
  • 31

1 Answers1

1

As I done search on your case your possible bet is to use WGET command line tool. You can get it from here.

Use this to refer Recursive-Download.

Sample for using 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();
Irshad
  • 3,071
  • 5
  • 30
  • 51
  • Thank you. Just trying to figure out where it downloads the file or if I could direct it to C:\downloads – DDJ Dec 09 '15 at 05:52