UnauthorizedAccessException When downloading a .exe file via FTP

-1

I've written a really simple Command Line app to check a private server for updated files.

The app works fine, it's suposed to write a list of out-of-date files from the local installation and then download the updated ones via FTP.

As I said, it works fine UNTIL it has to download the Interfaz.exe file. At that point it launches the following exception:

System.Net.WebException
  HResult=0x80070005
  Mensaje = An exception occurred during a WebClient request.
  Origen = System.Net.WebClient
  Seguimiento de la pila:
   at System.Net.WebClient.DownloadFile(Uri address, String fileName)
   at System.Net.WebClient.DownloadFile(String address, String fileName)
   at Launcher.Program.ActualizarPorFTP(String direccionDescargaActualizacion, String direccionInstalacion) in C:\Users\Diego Fonseca\source\repos\Lanada84\NSIG\Launcher\Program.cs:line 128
   at Launcher.Program.CompruebaArchivos(String actualizacion, String instalacion, Boolean usarConexionFTP) in C:\Users\Diego Fonseca\source\repos\Lanada84\NSIG\Launcher\Program.cs:line 184
   at Launcher.Program.Main(String[] args) in C:\Users\Diego Fonseca\source\repos\Lanada84\NSIG\Launcher\Program.cs:line 84

  Esta excepción se generó originalmente en esta pila de llamadas:
    [Código externo]

Excepción interna 1:
UnauthorizedAccessException: Access to the path 'C:\NSIG\Gestion\Interfaz.exe' is denied.

The code that performs the download is as follows:

using (WebClient ftpClient = new WebClient())
            {
                ftpClient.Credentials = new NetworkCredential("fakeUser", "fakePassword");

                for (int i = 0; i <= directories.Count - 1; i++)
                {   
                        string path = direccionDescargaActualizacion + directories[i].ToString();
                        string trnsfrpth = direccionInstalacion + directories[i].ToString();
                        Console.WriteLine("Descargando archivo " + directories[i].ToString());

                        ftpClient.DownloadFile(path, trnsfrpth);  //Exception raises here

                        Console.SetCursorPosition(0, Console.CursorTop - 1);
                        Console.WriteLine("Descargando archivo " + directories[i].ToString() + " - OK");   
                }
            }

I've checked Antivirus configuration (and completely disabled it for testing). Manually copying the file works just fine (as the command line app launches the .exe file after full update).

The FTP server is up and running (as it downloads another files before reaching the .exe).

Don't know what else to check, and it seems obvious to me that the problem is about copying an .exe file.

Hope you can help me find a solution to this.

Best regards. Diego Fonseca

c#
ftp
unauthorizedaccessexcepti

1 Answer

0

Ok, found it by myself...

When running the app as Administrator the file is copied without any problems.

Sorry for bothering you guys...


User contributions licensed under CC BY-SA 3.0