FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(@"ftp://ftp.somesite.com/somefile.txt");
request.Credentials = new NetworkCredential(@"ftp_user", @"ftp_password");
request.Method = WebRequestMethods.Ftp.DownloadFile;
using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
{
using (StreamReader in_stream = new StreamReader(response.GetResponseStream()))
{
using (StreamWriter out_stream = new StreamWriter(@"C:\localfile.txt", false))
{
char[] buffer = new char[1024];
while (!in_stream.EndOfStream)
{
int bytes_read = in_stream.Read(buffer, 0, buffer.Length);
out_stream.Write(buffer, 0, bytes_read);
}
}
}
}
|