1

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?

1 Answer 1

1

Download the file to HttpResponse.OutputStream:

HttpResponse response = HttpContext.Current.Response;

response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);

client.DownloadFile(remotePath + fileName, response.OutputStream);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.