• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Building an FTP Servlet

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys

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?

//yzfr1
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're reading more into that description than is actually there.

All your servlet would do would be this:

  • Take the file name from the HTTP request
  • Establish a connection to the FTP server
  • Send a GET request to the FTP server for that file
  • 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
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.

    Thanks!
     
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Paul Clapham
    Marshal
    Posts: 28193
    95
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Allright, cheers guys, appreciate it
    Will post back if I encounter any problems
     
    Tobias Ericsson
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic