开发者

Is it possible to download file from FTP using Javascript?

开发者 https://www.devze.com 2023-02-18 13:05 出处:网络
Suppose, I\'ve a FTP URL (ftp://xyz.org/file.zip). If I type this in the browser manually, then hit enter, the browser will start to download the file.zip and would ask me save it on harddisk.

Suppose, I've a FTP URL (ftp://xyz.org/file.zip). If I type this in the browser manually, then hit enter, the browser will start to download the file.zip and would ask me save it on harddisk.

My question is: Is it possible to write a script in JavaScript, which when run should download the file with all these options (separately)?

  • in a new window?
  • in a new t开发者_如何学Cab in the same window?
  • without opening a new window or tab?


new window or new tab is controlled by the user's preference, and you can't override that. But to open your URL in a new tab/window you would use

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

to request it without opening a new window just

window.location = 'ftp://xyz.org/file.zip';


At the most basic just make a link like this:

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

In JS just open a window with that url.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号