I wrote this code to download a file from an FTP server. When the program tries to download and save the file, I get an access denied error. I tried opening the program with admin rights, but it gives the same error.
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(txtFTPuser.Text,
txtFTPpassword.Text);
/*List all directory files*/
byte[] fileData = request.DownloadData(fullDownloaPath);//dnoces.dreamhost.com
FileStream fi = File.Create(downloadTo);
fi.Write(fileData, 0, fileData.Length);
fi.Close();
MessageBox.Show("Completed!");

You need to provide the full file path in your call to
File.Create. Right now, you’re trying to overwrite your “Games” directory with the file you’re downloading, and that’s no good.Try setting
downloadToto something likeC:\Users\agam\Desktop\Games\myfile.extinstead of, as it’s likely set to now,C:\Users\agam\Desktop\Games\.As an aside, there are two obvious improvements to your code I’d encourage you to look at:
DownloadFilemethod ofWebClient, rather thanDownloadData, to save you some effort.usingcall to ensure that it’s closed even if your method encounters an exception. Otherwise, you risk a leak of resources held by the client.For example: