aspose file tools*
The moose likes Servlets and the fly likes Using GenericServlet for FTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Using GenericServlet for FTP" Watch "Using GenericServlet for FTP" New topic
Author

Using GenericServlet for FTP

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

How to extend GenericServlet to support FTP . What are the steps involved. I am not only interested in using GenericServlet to support FTP and not any other solution. Thanks./


Groovy
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

It is not really possible to make servlets for handling other protocols than HTTP.

The protocol is handled by the servlet container, not the servlet itself. If you want to have FTP commands sent to a servlet, you need a special servlet container that handles the FTP protocol and sends the received FTP commands to a servlet. As far as I know there are no servlet containers available that can do this.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Jesper is right -- since Tomcat is open-source you COULD dive into the guts of the container and do it but that's a PhD-thesis sized project...

Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245
According to the the Javadoc the only method that you must override is service(). You could look at the patterns used in HttpServlet to get some ideas. For the FTP protocol I could see things like doPut(), doGet(), doList(), and so on. You service() method would parse appropriately and call those methods on a FTPServlet.

The real issue, as was pointed out, is that the container handles the actual protocol. This is a not so subtle side effect of the J2EE servlet specification. Sure, you could have a FTPServlet, a SMTPServlet, and whatever other kind of protocol you want. But at the lowest level something has to be listening for a connection on a particular port and route packets to and from that port appropriately. Tomcat follows the servlet spec but doesn't have a Connector (a Tomcat term) for FTP. It really wouldn't be too bad to write one. Looking at the docs for Http11Processor you'll see that it implements two interfaces. Basically you want to create your own connector for Tomcat.

All of this is great, but forget about portability. If you want this to work in WebLogic or WebSphere you'll have to figure out their API's too.

I don't know that this is quite PhD level but is isn't trival either.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Thanks guys for your replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using GenericServlet for FTP