apache Silverlight FTP 上传
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1127981/
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
Silverlight Ftp Upload
提问by Curtis
I'm working on trying to ftp a file to the server through a silverlight application. Where the location to upload the file on server file system, exists outside the sandbox area for the web server. In this case the web server root exists at "C:\test\www\" and the location to upload the file will exist at "C:\User\Uploads". In this scenerio i'm not sure if Http POST will work (doesn't that use the web server root). I just need to upload the file selected by the user to a different location that may exist outside the sandbox. With silverlight i'm thinking sockets are my last option based on the limited port range for silverlight being 4502-4532. Can i do this using WebClient and Http POST? Can i make an ftp connection through silverlight or javascript?
我正在尝试通过 Silverlight 应用程序将文件通过 ftp 传输到服务器。在服务器文件系统上上传文件的位置存在于 Web 服务器的沙箱区域之外。在这种情况下,Web 服务器根目录位于“C:\test\www\”,上传文件的位置将位于“C:\User\Uploads”。在这个场景中,我不确定 Http POST 是否可以工作(不使用 Web 服务器根)。我只需要将用户选择的文件上传到沙箱外可能存在的不同位置。对于 Silverlight,我认为套接字是我最后的选择,因为 Silverlight 的端口范围是 4502-4532。我可以使用 WebClient 和 Http POST 来做到这一点吗?我可以通过 Silverlight 或 javascript 建立 ftp 连接吗?
采纳答案by Jeff Wilcox
This is an interesting scenario, since it sounds like you are doing this all on the same machine (both client and server). I am responding to the vague original question, and would love additional data to help answer this completely.
这是一个有趣的场景,因为听起来您是在同一台机器(客户端和服务器)上执行所有这些操作。我正在回答模糊的原始问题,并希望获得更多数据来帮助完全回答这个问题。
FTP uploading itself is not supported by Silverlight, but the concept of uploading a file is, through an HTTP stream of data.
Silverlight 不支持 FTP 上传本身,但上传文件的概念是通过 HTTP 数据流。
If you want to do an HTTP upload from a client machine to the server: You can use the OpenFileDialog controlin Silverlight 2 and 3 to read that data, then use WebClient to upload it.
如果您想从客户端机器向服务器进行 HTTP 上传:您可以使用Silverlight 2 和 3 中的OpenFileDialog 控件读取该数据,然后使用 WebClient 上传它。
If you want to do a download from something your web server can send, to the client machine, then you'd need to use Silverlight 3 or newer, which features a SaveFileDialog control.
如果您想从 Web 服务器可以发送的内容下载到客户端计算机,则需要使用 Silverlight 3 或更新版本,它具有SaveFileDialog 控件。
All Silverlight file dialogs require a user-initiated action for them to work, function, and the user will need to select the file name(s) for security purposes.
所有 Silverlight 文件对话框都需要用户启动的操作才能工作和运行,并且出于安全考虑,用户需要选择文件名。
Hope this helps!
希望这可以帮助!
回答by bar10dr
As long as the ftp server is on the same host as the silverlight app you can use sockets and code your own ftp client, its not very hard and there's plenty of examples out there.
只要 ftp 服务器与 Silverlight 应用程序在同一主机上,您就可以使用套接字并编写自己的 ftp 客户端代码,这并不难,并且有很多示例。
回答by Andreas Niedermair
In the meantime, name it Silverlight 5, Sockets got an update: with ClientAccessPolicy.xmlthe port-range got boosted and an in-browser elevated-trust mode is available.
与此同时,将其命名为 Silverlight 5,Sockets 得到了更新:ClientAccessPolicy.xml端口范围得到提升,并且浏览器内的提升信任模式可用。
Therefore I've created sharpLightFtpto enable rudimental Ftp.
因此我创建了sharpLightFtp来启用基本的Ftp。
回答by AnthonyWJones
Assuming your server is ASP.NET based I would use a simple WebClient POST into a .ashx handler. Have the handler write the body of the post to a file in "C:\User\Uploads".
假设您的服务器是基于 ASP.NET 的,我将使用一个简单的 WebClient POST 到 .ashx 处理程序。让处理程序将帖子正文写入“C:\User\Uploads”中的文件。

