从ASP.NET页上的SFTP服务器下载文件
我在Ubuntu 16.04上有SFTP服务器,在ASP Core 2.0上有一个具有REST API的站点.
I have SFTP server on Ubuntu 16.04 and a site with REST API on ASP Core 2.0.
问题是我想提供指向服务器上文件的直接链接,但是我不知道该怎么做.我想它必须由API完成,但是怎么办呢?我可以通过API下载文件并将其提供给用户,但是会有两次(用于从服务器从API下载和由用户从API下载).我在某些站点上看到了带有一些访问令牌的文件链接.可能我应该使用这种方式吗?有什么想法吗?
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?
但是会有两次时间
but there will be twice time
不一定.
您只需要使用流API并将数据从输入SFTP流连续传递到输出HTTP流.
You just have to use a streaming API and pass the data continuously from an input SFTP stream to an output HTTP stream.
以下是FTP的一些示例:
Here are some examples for FTP:
与SFTP相同,只是您需要使用 SFTP库(其中不支持SFTP.NET),而不是 FtpWebRequest
.
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
.
特别是 SSH.NET库具有流API.检查其 SftpClient.DownloadFile
方法:
Particularly SSH.NET library has a streaming API. Check its SftpClient.DownloadFile
method:
public void DownloadFile(string path, Stream output, Action<ulong> downloadCallback = null)
您可能会像这样简单地使用它:
You can probably use it simply like:
sftpClient.DownloadFile(path, Response.OutputStream);