This is an function that downloads a single file from an FTP server and saves it to disk This is my first time doing anything with FTP, please let me know if i have missed anything.
public void DownloadFile(string fileloc, string saveLoc)
{
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(fileloc);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(Username, Password);
using (var response = (FtpWebResponse)request.GetResponse())
{
using (var fileStream = File.Create(saveLoc))
{
response.GetResponseStream().CopyTo(fileStream);
}
}
}
catch (Exception EX)
{
throw EX;
}
}