I am trying to download files from Raspberry Pi with ftp protocol. I have to press a button to download a file Press the button and access to 'C:\Users\Monster\Desktop\ftp' is denied.' I'm getting an error. I installed the app manifest, added the necessary permission line for admin, right clicked on the folder I want to download and checked the permissions in the security section, all permissions are open. I couldn't find the reason for the error I got, can you help me, I wish you a good day.
int bufferSize = 2048;
FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create("ftp://10.252.26.72//media/pi/Video1/video.mp4");
ftpRequest.Credentials = new NetworkCredential("pi", "1");
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = true;
ftpRequest.KeepAlive = true;
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
Stream ftpStream = ftpResponse.GetResponseStream();
FileStream localFileStream = new FileStream(@"C:\Users\Monster\Desktop\ftp", FileMode.Create);
byte[] byteBuffer = new byte[bufferSize];
int bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
try
{
while (bytesRead > 0)
{
localFileStream.Write(byteBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(byteBuffer, 0, bufferSize);
}
}
catch (Exception ex)
{
}
localFileStream
needs ausing
. LikewiseftpResponse
andftpStream
also needusing
. Also: don't bother with thewhile
, just useftpStream.CopyTo(localFileStream);
And don't swallow exceptions.ftp
a directory?