In my website I have listed the ftp folder file, when user click the download button i call the code below, then download the file to their c drive. However I getting error Access to the path 'C:\myvideo.flv' is denied.
Code is running on server, and needed to save to local PC drive.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
Did I miss sometime in my FtpWebRequest
or other cause this issue.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTPRequest_Host + "myvideo.flv");
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.KeepAlive = true;
request.UsePassive = true;
request.UseBinary = true;
request.Credentials = new NetworkCredential(FTPRequest_Username, FTPRequest_Password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
using (FileStream writer = new FileStream(@"C: \\" + "myvideo.flv", FileMode.Create, FileAccess.ReadWrite))
{
long length = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[2048];
readCount = responseStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
writer.Write(buffer, 0, readCount);
readCount = responseStream.Read(buffer, 0, bufferSize);
}
}
reader.Close();
response.Close();