Web 应用程序处理用户从 SFTP 服务器下载文件的请求的功能

发布于 2024-08-05 00:33:56 字数 983 浏览 3 评论 0原文

在我们的 Java Web 应用程序中,客户希望将一些大文件上传到 SFTP 服务器并直接从那里下载。客户不想使用任何第三方工具,而是希望应用程序本身具有此功能。

文件上传部分已由 JFileUpload 小程序组件和 JFileUpload 处理。图书馆。文件上传后,我可以找出存储文件的确切位置。上传的文件将作为链接显示给用户,用户可以单击该链接进行下载(如 HTTP 或 FTP 文件链接)。

所以我必须决定从 SFTP 服务器下载文件的策略。

一种选择是解析请求,然后连接 SFTP 服务器并通过 HTTP 服务器传输文件。但这里的文件将通过 HTTP 而不是 SFTP 下载,而且它无法达到使用 SFTP 的目的。

我能想到的另一个选择是通过小程序,同样是上传。一旦对 SFTP 文件的请求到达 HTTP 服务器,它将启动一个包含小程序的页面,该小程序具有目录浏览器,供用户决定保存路径。用户选择保存位置后,文件将自动开始从 SFTP 服务器下载到该位置。这样连接就完全是SFTP了。

我想知道第二种方法的可行性有多大,以及是否有任何重要的事情需要我处理。哪些 SFTP 库最适合此类操作?

此外,如果有其他更好的选择来进行上述活动,请告诉我。

编辑

看来这篇文章看起来像是关于如何从 SFTP 服务器下载的建议请求(可能来自标题,但我想不出任何其他标题!!)。感谢您对 API 的建议,但对我们来说更重要的问题是找到一种方法,让用户从 SFTP 服务器下载文件的请求是通过安全的 SSH 而不是 HTTP 来完成的。现在,使用提到的 API,我们可以很好地将文件从 SFTP 服务器下载到 HTTP 服务器的文件系统,但之后,如果我们必须将同一文件重定向到用户的计算机,我们就必须使用 HTTP,而这正是我们想要避免的。

我们的第二个想法是使用带有小程序的页面来在用户客户端和 SFTP 服务器之间启动 SFTP 会话,以解决上述问题。

实施的难度有多大?我们的做法应该是什么? 如果还有其他更好的&完成相同任务的更简单方法请提出建议。

In our Java web application, customer wants to upload some large files to a SFTP server and download directly from there. The customers do not want to use any third party tool rather they want this functionality in the application itself.

The file upload part has been taken care of by the JFileUpload applet component & libraries. Once the file gets uploaded I could figure out the exact location of the stored file. And that uploaded file will be shown to the users as a link which they will click to download (like an HTTP or FTP file link).

So I've to decide the strategy for downloading the file from the SFTP servers.

One option is to parse the request, then connect with the SFTP server and stream the file via HTTP server. But here the file will be downloaded over HTTP rather SFTP and moreover it will not serve the purpose of using SFTP.

Another option which I could think of is via an applet, again like upload. As soon as the request for the SFTP file comes to the HTTP server, it will launch a page containing an applet having a directory browser for users to decide the save path. Once the user selects the save location, the file will automatically start downloading to that location from the SFTP server. In this way the connection will be completely SFTP.

I want to know how much feasible the second approach is and if there are any important things I'll have to take care of. Which SFTP libraries are the best to use for this type of operations?

Moreover, please let me know if there are other better options to do mentioned activity.

Edit

It seems this post looks like a request for suggestion on ways to download from SFTP server (may be from the heading but I could not think of any other heading!!). Thank you for the suggestions on the APIs to do that but the more important issue for us is to figure out a way where a user's request to download a file from SFTP server is done over secure SSH rather than over HTTP. Now using the mentioned APIs we could very well download the files from the SFTP server to the HTTP server's filesystem but after that if we have to redirect the same file to the user's machine we have to use HTTP and that is what we want to avoid.

Our second thought approach of using a page with an applet which will initiate a SFTP session between user's client and SFTP server is to address the above concern.

How difficult will it be to implement and what should be our approach in this regard?
And if there is any other better & easier way to do the same task then please suggest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甜尕妞 2024-08-12 00:33:56

对于这种事情,我更喜欢 Commons-VFS 。它抽象出实际的文件系统类型,并允许您使用标准接口,而不管底层实现如何。它又依赖于实际系统的其他库,特别是用于 SFTP 的 JScsh。

I favor Commons-VFS for this kind of thing. It abstracts out the actual file system type and lets you work with a standard interface regardless of the underlying implementation. It in turn depends on other libraries for the actual systems, in particular JScsh for SFTP.

盗琴音 2024-08-12 00:33:56

我建议使用 JSch,Java 安全通道。它是 SSH2 的纯 Java 实现。除了几乎所有其他 SSH2 选项(XForwarding、端口转发等)之外,它还提供了执行 SFTP 的好示例。我们在许多项目中使用它,并且没有遇到任何问题。我什至将其 GSS-API (Kerberos) 支持绑定到本机 Kerberos 实现中,并且运行良好。它是 BSD 许可的,因此无论是否商业化,您都不应该在许可方面遇到太多问题。

我认为使用 JSch 构建小程序非常简单。最大的问题是确保您的小程序已签名并有权写入/读取本地文件以及连接到相关 SSH 服务器。

I recommend using JSch, Java Secure Channel. It is a pure Java implementation of SSH2. It has good examples for doing SFTP in addition to pretty much every other SSH2 option (XForwarding, port forwarding, etc.). We use it in a number of our projects, and have not had any issues. I have even tied it's GSS-API (Kerberos) support into a native Kerberos implementation and it worked well. It is BSD licensed, so commercial or not, you shouldn't have much issues with licensing.

I see building an applet using JSch to be pretty simple. Biggest issue will be to make sure your applet is signed and has permissions to write/read local files and connect to the SSH servers in question.

假面具 2024-08-12 00:33:56

客户永远是对的,因此,虽然需求对我来说是糟糕的架构,但我对此表示同情,并尽力帮助您解决问题。

小程序方法还可以,但对于网络应用程序来说似乎有点笨拙。有 javascript sftp 库。 支持 sftp,并且会给 Web 应用程序带来更自然的感觉而不是仅仅为了提供文件传输而弹出一个小程序。它不是免费的,但也不是那么昂贵。它仍然使用底层的小程序来实现文件传输,只是不向用户显示 java 屏幕。

The customer is always right, so while the requirement screams bad architecture to me, I'll just extend my sympathy on that and try to help you with the problem.

The applet approach is OK, but seems kind of clunky for a web app. There are javascript sftp libraries out there. This one supports sftp and will give a much more natural feel to a web application than poping up an applet just for the sake of providing a file transfer. It isn't free, but it isn't that pricy either. It still uses an applet under the hood to effect the file transfer, it just doesn't present a java screen to the user.

很快妥协 2024-08-12 00:33:56

您是指 SFTP 还是 FTPS(基于 SSL 的 FTP)?
如果您确实使用 SFTP,请查看此处: http://www.spindriftpages.net/blog/dave/2007/11/27/sshtools-j2ssh-java-sshsftp-library/comment-page-1/

Did you mean SFTP or FTPS (FTP over SSL)?
If you realy ment SFTP, have a look here: http://www.spindriftpages.net/blog/dave/2007/11/27/sshtools-j2ssh-java-sshsftp-library/comment-page-1/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文