从ASP.NET页上的SFTP服务器下载文件 [英] File download from SFTP server on ASP.NET page

查看:81
本文介绍了从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);

这篇关于从ASP.NET页上的SFTP服务器下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆