The function below will perform the FTP and return the StreamReader to read the newly downloaded file:
using System;
using System.Security.Permissions;
using System.Net;
using System.IO;
System.IO.StreamReader AnonFTP(string theFileToDownload, string theLocalFile)
{
try
{
WebClient request = new WebClient();
// FTP site uses anonymous logon.
request.Credentials =
new NetworkCredential("anonymous","YourEmail@YourHost.com");
request.DownloadFile(theFileToDownload,theLocalFile);
return new System.IO.StreamReader(theLocalFile);
}
catch
{
return null;
}
}
Sample Invocation:
AnonFTP("ftp://x.com/dat.txt", "C:\\test.txt");
No comments:
Post a Comment