Building an FTP Servlet

I just read this wikipedia article about "FTP servlets" which can wrap FTP traffic to HTTP(S) and I just decided to try and create one.

Now I thought my version of it would function like this: It receives a file request from another webapp which in turn got it from a user. It opens a FTP transfer from a local FTP server and 'wraps' this into HTTPS and returns this to the first webapp for the user to download.

It was just a sudden idea but it sort of appeals to me . I'm just at a loss as to where to start, both how to open this FTP connection and how to "wrap" it into HTTPS. I mean, is there any existing libraries that can do these things or..? Any suggestions?

Stream the response from the FTP server to the servlet's output stream

Which is exactly what you started to describe. I think you just got carried away with the word "wrap" and thought it was some kind of advanced technique.

Tobias Ericsson
Greenhorn

Joined: Apr 27, 2009
Posts: 6

posted Feb 10, 2011 15:59:31

0

Wow, yes, I think you're absolutely right .

Thanks for clearing that up, seems a much simpler task all of a sudden!

For the connection and GET request to the FTP server, will I need a special library, because thats not included in the standard JavaEE API, correct? Some googling turned up org.apache.commons.net.ftp, would that be a good option you think?

Oh, and also, how do you mean I should "stream the response" to the output stream? Hmm, maybe that part will solve itself once I get a look at the API for this.

Apache Commons Net is a very good library (make sure to check out what else it has to offer, so it's in the back of your brain next time you need to address a networking problem), and its FTP client is rock solid - it's a good choice.

Tobias Ericsson wrote:Oh, and also, how do you mean I should "stream the response" to the output stream? Hmm, maybe that part will solve itself once I get a look at the API for this.

You're going to get an InputStream from the FTP object. Just copy all of the bytes from that to the OutputStream which is your servlet's response.

Tobias Ericsson
Greenhorn

Joined: Apr 27, 2009
Posts: 6

posted Feb 11, 2011 02:14:52

0

Allright, cheers guys, appreciate it Will post back if I encounter any problems

Tobias Ericsson
Greenhorn

Joined: Apr 27, 2009
Posts: 6

posted Feb 12, 2011 07:44:12

0

Hi again.

I got a bit sidetracked, I got it into my head to try and make this app as "secure" as possible, so I thought I'd venture into letting tomcat handling the authentications using the FORM method in the web.xml. I did lots of googling and then created this "JDBCRealm" in the server.xml to make it connect to my mysql database to authenticate users, though it doesn't seem to work..

Heres the additions to server.xml

And to web.xml

And nothing happens basically, the login.jsp is never shown when accessing the resources. I think the problem is that I don't have a auth-constraint defining roles, but since its supposed to connect to the DB to get the roles I'm not sure what to put there...

I'm sorry, I know this is really OT and I should probably create a new thread about it, I just thought that if its just something small that I've missed then you could just point it out? thanks