only My site

Wednesday, July 23, 2008

Copy File from remote location (HTTP, https, FTP..)


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

No comments: