error "Access to the path 'MyPathLocal' is denied." when downloading an FTP file to Local c #

0

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();
            }
        }
    
asked by LopezAi 26.01.2018 в 11:10
source

0 answers