15

我有一个 webDav CORS 插件,可用于在 webDav 服务器上 POST/PUT/GET/REMOVE/ALLDOCS 文件。

我现在想为 FTP 做同样的事情,但我正在努力让xmlhttprequest-syntax 工作(我只是得到错误0)。

Mozilla上的这个页面说它也可以xmlhttprequests用于文件和 ftp,但我在任何地方都找不到工作示例或教程。

这就是我正在尝试的,它返回access to restricted URI denied

function reqListener () {
  console.log(this.responseText);
}

var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.open("GET", "ftp://<username>:<passeword>@mydomain.de/folder/test.txt", true);
oReq.send();

我还尝试了一个常规的 Ajax 请求

$.ajax({
  url: "ftp://sharedspace.domain.provider.com/folder/test.txt",
  type: "GET",
  async: true,
  dataType: "text",
  crossdomain : true,
  headers : {
    user: "<username>",
    password: "<password>"
  },
  success: function(e){
    console.log("success");
    console.log(e);
  },
  error: function(e){
    console.log("error");
    console.log(e);
  },
}); 

这也不起作用,返回0状态码。

问题:为.
_XMLHTTPREQUESTFTP

谢谢!

编辑:
我找到的唯一有用的链接是这里的这个页面,但它只是一些零碎的信息,我无法将它们拼凑在一起。

编辑
也许也有用的链接

4

2 回答 2

17

尽管 Mozilla MDN 文档引用了 xmlHttpRequest 支持文件和 ftp,但没有一个主要浏览器执行 AFAIK。file://如果您想开发/测试任何 xmlHttpRequest 东西,因为它不起作用,这就是您需要从某种服务器提供 Web 项目的原因之一,即使它在同一台机器上。

微软特别声明IE 只支持 http/https。它的 W3C 规范还说该规范仅适用于 HTTP/HTTPS,但“某些实现支持 HTTP 和 HTTPS 之外的协议,但本规范未涵盖该功能”。

至于 CORS,它专门用于 HTTP/HTTPS。该规范是关于使用 HTTP 标头的。请参阅此处的 W3C 规范。FTP 没有任何与 HTTP 等效的标头类型。

于 2013-02-26T22:46:47.810 回答
1
oReq.open("PUT", "ftp://`<username`>:`<password`>@mydomain.de/folder/test.txt", true);

req.setRequestHeader('Content-Type', "text/plain");

req.send("Content of test.txt. This will be in test.txt");
于 2013-02-26T22:52:23.777 回答