Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Client side download from FTP Server (FTPClient from Apache) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Client side download from FTP Server (FTPClient from Apache)" Watch "Client side download from FTP Server (FTPClient from Apache)" New topic
Author

Client side download from FTP Server (FTPClient from Apache)

Vincent Paranpan
Greenhorn

Joined: Sep 16, 2010
Posts: 13
Hello!

I have a question regarding Apache's FTPClient.retrieveFile(), here's the situation, I've created a simple web application and I was planning on letting the users download files from a FTP Server whenever the user clicks a button or link on my web page. I found a library from Apache that contains FTP manipulations, and I want to use it as the method of downloading files from the FTP Server into the local drive of the user.

How will I achieve this?

I've tried to using retrieveFile() but it only downloads the files from the FTP Server into the Application Server not to the local drive (Client Side) of the user..

Is there a way I can do this?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Is there a way I can do this?

Not unless there's an applet or JavaWebStart application on the client that can run this code. But for a simple file download via FTP this isn't necessary, since browsers have FTP built in. If memory serves, the URL syntax would be something like "ftp://user:password@192.168.10.1/directory/TextFile" (check the appropriate RFC for how exactly an FTP URL looks).
Vincent Paranpan
Greenhorn

Joined: Sep 16, 2010
Posts: 13
You're right Lester, I tried it and it works, I used a hotlink on my page and whenever the user clicks on it the page displays the contents of the file.


How can I automate the download of file without displaying the contents of it on the web page? If this is not achievable I'll have to stick with the client side jar to invoke the download.

Thanks!
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
If the file has a filename extension (like .txt, .pdf etc.), then the browser mechanism for dealing with downloads should kick in. In other words, it would be up to the user to configure their browser to display or save the file. Not sure how browser handle files that have no extension.
Vincent Paranpan
Greenhorn

Joined: Sep 16, 2010
Posts: 13
Yeah, so basically it all depends on my browser whether or not I have TXT/PDF reading plugins / capabilities..

I tried the same code on a different file type (jar, zip), it shows a save prompt.

Thanks for the answer Lester it really gave me an idea on how to solve this.
 
jQuery in Action, 2nd edition
 
subject: Client side download from FTP Server (FTPClient from Apache)