Javascript 通过Javascript从FTP下载文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4594798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Download file from FTP via Javascript
提问by AnarchistGeek
I have a got a file server and a web server. They are running on physically different machines.
我有一个文件服务器和一个网络服务器。它们在物理上不同的机器上运行。
I would like to download a file from the FTP server via JavaScript. The reason I have to do it via JavaScript is that I have an external application and I can only inject JavaScript into that application.
我想通过 JavaScript 从 FTP 服务器下载文件。我必须通过 JavaScript 来完成的原因是我有一个外部应用程序,我只能将 JavaScript 注入到该应用程序中。
Basically, I need to specify ftp address username and password. But I am concerning about security as people can view FTP credentials.
基本上,我需要指定ftp地址用户名和密码。但我担心安全性,因为人们可以查看 FTP 凭据。
What is the best way to implement such scenario?
实现这种场景的最佳方法是什么?
Thanks for your help
谢谢你的帮助
Regards
问候
回答by Alex Vidal
Javascript only speaks HTTP and WebSockets (on newer browsers), and not FTP. In that situation, keeping it all on the client-side, you'd probably have to write a Flash or Java applet that handles the actual FTP protocol, and interface with Javascript to provide interactivity.
Javascript 只说 HTTP 和 WebSockets(在较新的浏览器上),而不是 FTP。在这种情况下,将所有内容都保留在客户端,您可能必须编写一个 Flash 或 Java 小程序来处理实际的 FTP 协议,并与 Javascript 接口以提供交互性。
Unless you're planning on redirecting the browser to the ftp site, passing in the username and password? Are you concerned about the users getting the FTP information, or are you concerned with man-in-the-middle attacks sniffing the plaintext FTP credentials?
除非您打算将浏览器重定向到 ftp 站点,否则传入用户名和密码?您是担心用户获取 FTP 信息,还是担心中间人攻击嗅探明文 FTP 凭据?
回答by John Giotta
JavaScript doesn't support FTP. What you need is a server-side or a more robust client-side language to access the remote server.
JavaScript 不支持 FTP。您需要的是服务器端或更强大的客户端语言来访问远程服务器。
回答by German Rumm
If by "downloading" you mean "prompt user to save a file from external link" (which basically means open a new window with URL that points to a file) then you can just point user to a script you have control over.
如果“下载”是指“提示用户从外部链接保存文件”(这基本上意味着打开一个带有指向文件的 URL 的新窗口),那么您只需将用户指向您可以控制的脚本。
window.open('http://myserver/get_file/filename');
And your server-side get_file
script will do all the work of connecting to a FTP and fetching a file
您的服务器端get_file
脚本将完成连接到 FTP 和获取文件的所有工作
回答by Brett
How about creating an iframe and setting the url to ftp://whatever?
创建一个 iframe 并将 url 设置为ftp://whatever怎么样?