简体   繁体   English

UnauthorizedAccessException 通过 FTP 下载 a.exe 文件时

[英]UnauthorizedAccessException When downloading a .exe file via FTP

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.该应用程序运行良好,它应该从本地安装中写入过期文件列表,然后通过 FTP 下载更新的文件。

As I said, it works fine UNTIL it has to download the Interfaz.exe file.正如我所说,它工作正常,直到它必须下载 Interfaz.exe 文件。 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).手动复制文件就可以了(因为命令行应用程序会在完全更新后启动 .exe 文件)。

The FTP server is up and running (as it downloads another files before reaching the.exe). FTP 服务器已启动并正在运行(因为它会在到达 .exe 之前下载另一个文件)。

Don't know what else to check, and it seems obvious to me that the problem is about copying an.exe file.不知道还要检查什么,对我来说,问题似乎很明显是关于复制一个 .exe 文件。

Hope you can help me find a solution to this.希望您能帮助我找到解决此问题的方法。

Best regards.此致。 Diego Fonseca迭戈·丰塞卡

Ok, found it by myself...好吧,我自己找的……

When running the app as Administrator the file is copied without any problems.以管理员身份运行应用程序时,文件被复制而没有任何问题。

Sorry for bothering you guys...很抱歉打扰各位了...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM