Implementing ftp using Javascript

2019-02-19 03:59发布

问题:

I dont understand why cant javascript make ftp calls?. Why do we have to make such a request using server?

Even Browsers have ability to authenticate and browse a ftp server. Maybe use browser api's to do it?

回答1:

Ok, answering my own question here.

I went through Mozilla docs on XMLHTTPRequest. It specifically says -

Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just XML, and it supports protocols other than HTTP (including file and ftp).

So, I am satisfied with this. JavaScript can make calls to ftp using this.



回答2:

Here are some links I came across, most seem to point you in the direction of writing server-side code to manipulate the FTP and then pass it to the user using javascript.

  • https://github.com/sergi/jsftp
  • https://gallery.technet.microsoft.com/scriptcenter/FTP-File-Manager-via-ca3a4260
  • Download file from FTP via Javascript

Browser Compatibility?

  • Chrome webRequest for extensions
  • Firefox XMLHttpRequest


回答3:

The title of this question suggests the requester is keen on understanding if an FTP transfer could be implemented using JavaScript. However looking at the the answer by the same requester it appears that the question was just to know if URLs with FTP protocols can be used with JS and possibly HTML tags. The answer is yes. Even a simple <a> tag supports FTP URLs in the href attribute. Hope this helps the new readers. And yes, the XMLHttpRequest AJAX object does enable calling a URL with an FTP protocol.

Cheers.



回答4:

There is a Javascript library at http://ftp.apixml.net/ that allows FTP file uploads via Javascript.

In this case, technically, the ftpjs server is making the FTP connection to the ftp server, but the instructions are being passed via Javascript. So this particular library is designed primarily to allow developers add a basic file upload mechanism without writing sever side code.

Under the hood, it uses the Html5 FileReader to read the file to a base64 string, and then posts this using Cors ajax back to the server.



回答5:

its very difficult to FTP data(BIGfile) to backup server without using HTTP protocol in a web application.

Lets say, S1-( Client Browser ), S2-(code container server), S3-(Files Backup server) and we want to upload 2gb file from s1 using FTP.

use case diagram

This can be done by "JavaApplet" . we can embed uploader applet in webapplication. This applet will run inside browser sand box.
go through link

sample code for ftp using applet

provided you have to enable java on your browser.



标签: browser ftp