8

I have a got a file server and a web server. They are running on physically different machines.

I would like to download a file from the FTP server via JavaScript. The reason I have to do it via JavaScript is that I have an external application and I can only inject JavaScript into that application.

Basically, I need to specify ftp address username and password. But I am concerning about security as people can view FTP credentials.

What is the best way to implement such scenario?

Thanks for your help

Regards

AnarchistGeek
  • 3,049
  • 6
  • 32
  • 47

4 Answers4

12

Javascript only speaks HTTP and WebSockets (on newer browsers), and not FTP. In that situation, keeping it all on the client-side, you'd probably have to write a Flash or Java applet that handles the actual FTP protocol, and interface with Javascript to provide interactivity.

Unless you're planning on redirecting the browser to the ftp site, passing in the username and password? Are you concerned about the users getting the FTP information, or are you concerned with man-in-the-middle attacks sniffing the plaintext FTP credentials?

Alex Vidal
  • 4,080
  • 20
  • 23
  • 1
    I can use server site scripting and redirect user to ftp site. if I specify ftp credentials, I am concerning users getting credentials and also attacks. I think the only secure way to use server side scripting. – AnarchistGeek Jan 04 '11 at 15:05
  • 1
    It is. That's the only way to make sure your credentials are not in the clear for everyone to see. – Alex Vidal Jan 04 '11 at 15:07
2

JavaScript doesn't support FTP. What you need is a server-side or a more robust client-side language to access the remote server.

John Giotta
  • 16,432
  • 7
  • 52
  • 82
1

If by "downloading" you mean "prompt user to save a file from external link" (which basically means open a new window with URL that points to a file) then you can just point user to a script you have control over.

window.open('http://myserver/get_file/filename');

And your server-side get_file script will do all the work of connecting to a FTP and fetching a file

German Rumm
  • 5,782
  • 1
  • 25
  • 30
  • You are right; I would like user to click on a link and save the file to local. Isnt there any way to do it without server side? I can use asp.net as server side scripting, but some files are huge(bigger then 1gb)... where I am going to define to show save as file dialog then? on server side? – AnarchistGeek Jan 04 '11 at 14:57
0

How about creating an iframe and setting the url to ftp://whatever?

Brett
  • 484
  • 6
  • 16