I have SFTP server on Ubuntu 16.04 and a site with REST API on ASP Core 2.0.
The problem is that I want to provide a straight link to a file on the server, but I don't know how to do it. I suppose it has to be done by API, but what the way? I can download the file by API and give it to the user, but there will be twice time (for download by API from the server and by user from API). And I saw on some sites a link to the file with some access token. May be I should use this way? Any ideas?
Not necessarily.
You just have to use a streaming API and pass the data continuously from an input SFTP stream to an output HTTP stream.
Here are some examples for FTP:
With SFTP it will be the same, just that you need to use an SFTP library (there's no SFTP support in .NET) instead of
FtpWebRequest
.Particularly SSH.NET library has a streaming API. Check its
SftpClient.DownloadFile
method:You can probably use it simply like: