JohnSouth wrote:
Hi
From within a c# program running on windows 2003 server I need to copy
individual files (mostly .doc, .pdf, .xml) from one web location
(http://... or https//...) to another.
Can someone suggest the best way to do this? Do I use ftp?
John South
Pangbourne UK
www.wherecanwego.com
Hello John, this should give you the basic idea
string RemoteFolder = @"http://yoursite.com/YourWebFolder/";
string RemoteFile = "yourfile.txt";
string url = RemoteFolder + RemoteFile;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new
StreamReader(webResponse.GetResponseStream(),Encod ing.ASCII);
string filecontent = sr.ReadToEnd();
StreamWriter sw = new StreamWriter("c:\mynewfile.txt");
sw.Write(filecontent);
sw.Flush();
sw.Close();
sr.Close();