Can I upload a file from FTP using Javascript?

Suppose I have an FTP address ( ftp://xyz.org/file.zip ). If I type this in the browser manually and then press enter, the browser will start downloading file.zip and ask me to save it to my hard drive.

My question is: is it possible to write a script in JavaScript, which at startup should download a file with all these parameters (separately)?

  • in a new window?
  • on a new tab in the same window?
  • without opening a new window or tab?
+4
javascript browser ftp
source share
2 answers

a new window or a new tab is controlled by user preference, and you cannot override this. But to open the url in a new tab / window, you have to use

 window.open('ftp://xyz.org/file.zip'); 

to request it without opening only a new window

 window.location = 'ftp://xyz.org/file.zip'; 
+8
source share

In the most basic case, just create a link:

 <a href="ftp://...." target="_blank">Download in new tab/window</a> 

In JS, just open a window with this URL.

+1
source share

All Articles