With SSH.NET, I am trying to trigger a file to be downloaded by the browser instead of directly writing it to the local file storage.
using(var saveFile = File.OpenWrite(@"Downloads")) {
result = client.BeginDownloadFile(remotePath + fileName, saveFile) as SftpUploadAsyncResult;
client.EndUploadFile(result);
}
The above code fails as my the application pool identity doesn't have permission to write files and I cannot give permission as I don't have Admin privileges to my computer.
So better option would be to trigger the download through browser which was working earlier with FtpWebRequest
.
But my current task is to convert the FTP download to SFTP download.
Can someone suggest the best way to trigger browser download?
Download the file to HttpResponse.OutputStream
:
HttpResponse response = HttpContext.Current.Response;
response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
client.DownloadFile(remotePath + fileName, response.OutputStream);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.