Reputation: 1689
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?
Upvotes: 1
Views: 749
Reputation: 202594
Download the file to HttpResponse.OutputStream
:
HttpResponse response = HttpContext.Current.Response;
response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
client.DownloadFile(remotePath + fileName, response.OutputStream);
Upvotes: 1