I have an webDav CORS plugin, which I can use to POST/PUT/GET/REMOVE/ALLDOCS files on a webDav server.
I now want to do the same for FTP, but I'm struggling to get the xmlhttprequest
-syntax to work (I'm just getting error 0
).
This page on Mozilla says it's possible to use xmlhttprequests
for file and ftp as well, but I cannot find a working example or tutorial anywhere.
This is what I'm trying, which returns 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();
I also tried a regular Ajax request
$.ajax({
url: ".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);
},
});
which also does not work, returning 0
status code.
Question:
What is the correct syntax to do a cross-domain XMLHTTPREQUEST
for FTP
.
Thanks!
EDIT:
The only useful link I found is this page here, but it's just bits and pieces of information and I couldn't puzzle them together.
EDIT
Maybe also useful link
I have an webDav CORS plugin, which I can use to POST/PUT/GET/REMOVE/ALLDOCS files on a webDav server.
I now want to do the same for FTP, but I'm struggling to get the xmlhttprequest
-syntax to work (I'm just getting error 0
).
This page on Mozilla says it's possible to use xmlhttprequests
for file and ftp as well, but I cannot find a working example or tutorial anywhere.
This is what I'm trying, which returns 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();
I also tried a regular Ajax request
$.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);
},
});
which also does not work, returning 0
status code.
Question:
What is the correct syntax to do a cross-domain XMLHTTPREQUEST
for FTP
.
Thanks!
EDIT:
The only useful link I found is this page here, but it's just bits and pieces of information and I couldn't puzzle them together.
EDIT
Maybe also useful link
- See stackoverflow.com/questions/5774497/… – Lee Meador Commented Feb 12, 2013 at 19:05
- Does FTP support CORS at all? – Bergi Commented Feb 12, 2013 at 19:39
- not sure at all, but curious to know if its possible. – frequent Commented Feb 12, 2013 at 22:55
- then the question should be is it possible ? first and foremost. I've been googling the same question , never read a positive answer on that matter. – mpm Commented Feb 26, 2013 at 23:10
- @mpm: yes it sure is hard to find something on this on Google. – frequent Commented Feb 27, 2013 at 8:43
2 Answers
Reset to default 19 +200Although the Mozilla MDN docs reference xmlHttpRequest supporting file and ftp none of the major browsers do AFAIK. It is one of the reasons why you need to serve your web projects from some sort of server, even if it is on the same machine, if you want to develop/test any xmlHttpRequest stuff since file://
doesn't work.
Microsoft specifically states that IE only supports http/https. The W3C spec for it also says that the spec is only for HTTP/HTTPS but that 'some implementations support protocols in addition to HTTP and HTTPS, but that functionality is not covered by this specification'.
As for CORS, it is specifically only for HTTP/HTTPS. The spec is all about using HTTP headers. See the W3C spec here. FTP doesn't have any equivalent type of header as HTTP.
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");