0

I'm creating a script in C# to download files from a FTP, and I'm using the method client.DownloadFile(), and, when I execute the program I get an error:

Access to "D:/DESTINO" is denied.

// Creates WebClient instance
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("userxxx", "passwordxxx");
// Download files and saves at
client.DownloadFile("ftp://ftpurl/file.xlsx", @"D:\DESTINO");

Thank you!

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
  • 1
    Is `D:\DESTINO` a folder? If so, `DownloadFile()` takes a _filename_ as the second argument, not a folder (see the [Microsoft documentation](https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient.downloadfile?view=netframework-4.8)). – Diado Feb 04 '20 at 14:48
  • Yeah, D:\DESTINO is a folder, so, i guess this awnsers the question, the parameter is incorrect. What method do i use to download the file to a folder? – Pedro Perondini Feb 04 '20 at 14:51
  • 2
    Try passing a filename to the second argument instead of a folder perhaps? - `D:\DESTINO\file.xlsx` – Diado Feb 04 '20 at 14:52
  • 2
    I don't think you need to change the method, just what you're passing it. `@"D:\DESTINO\SomeFileName.txt"` – Jimmy Smith Feb 04 '20 at 14:52
  • Well, that solves it, the script worked! Thank you guys! – Pedro Perondini Feb 04 '20 at 14:56

0 Answers0