Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

File download link

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a beginner in website development in java.
I wish to develop a website that allow users to download zip files from the web.
The zip files are stored in another FTP server (with login and password)
different from the web server.

I only know that one of the way is to add the link below in the webpage:

<A HREF="ftp://ftp.site.com/dirname/file.zip">;

We can also insert login and password to this link. But there is
security issue with this solution. When user click this link,
a dialog box is displayed to prompt user whether he want to download
this file. However, on the browser status bar, it shows the the full
path of the zip file with its login and password.

Is there any other solutions to solve this problem?
It would also be good if anyone could provide some sample source codes
to solve this problem.

Thanks in advance.
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would put a servlet in between the user and the FTP server. If the user clicks a link that indicates that he wants to download a file (the link should contain the file name or ID), then the servlet fetches the file (using an FTP client library like Jakarta Commons Net), and then streams the file contents to the browser. That way, the user doesn't see where the file originates.
 
harry flower
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks for your reply.

Do you have a simple code to demonstrate your solution probably a page
with a link that download the file?

Where should I store the file when it is ftp locally?
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't have a ready-made sample. Commons FTP is pretty easy to get into, though, if you're familiar with FTP at all. The javadocs of the FTPClient class should get you going.

Fellow ranch moderator Ben Souther has a code example of how to stream binary data to a browser here. You should store the file someplace that's not publicly accessible, e.g. a subdirectory of WEB-INF, as Ben suggests.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The closest thing I have is a sample app that streams images from file.
http://simple.souther.us
Look for SimpleStream.


As Ulf Mentioned, the commons net project is pretty easy to work with.
You can also pull a file from an FTP server using java.net.URLConnection but the commons net libraries give you more control and are easier to debug.

You should be able to substitute the inputStream returned from getResourceAsStream with the inputStream returned by either of the two libraries mentioned above. I do this with one of the projects I work on and it works well.
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic