I have to download a file from an FTP server to Local, but this error appears:
"Access to the path 'Path Local donde quiero descargarlo' is denied.".
My code is this:
public static bool FtpDownloadFile(string username, string password, string localFileFullPath, string remoteUriPath)
{
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(remoteUriPath);
ftpRequest.Credentials = new NetworkCredential(username, password);
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream stream = null;
StreamReader reader = null;
StreamWriter writer = null;
try
{
stream = ftpResponse.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);
writer = new StreamWriter(localFileFullPath, false);
writer.Write(reader.ReadToEnd());
return true;
}
finally
{
stream.Close();
reader.Close();
writer.Close();
}
}