Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Ftplet API is a simple API used to handle different FTP Server notifications. Apache FTP Server FtpServer is a Ftplet container, allowing administrators to deploy Ftplet to carry out a variety of complex FTP event handler tasks.

...

The Ftplet interface supports two lifecycle methods to provide initialization (the init() method) and shutdown (the destroy() method). Main processing is done in different notification methods, which take a FtpRequest FtpSession object and a FtpResponse FtpRequest object. All the notification methods return FtpletEnum object to indicate the future action.

There will be one instance of Ftplet object. Notification methods will be called from different connections running in different threads. So Ftplet implementation has to be thread-safe. Each connection will have its own request (FtpRequest) and response session (FtpResponse) objects. So FtpRequest and FtpRestonse objects are connection specificFtpRequest) objects.

Main Classes

FtpletEnum

This class encapsulates the return values of the ftplet methods. There are four static FtpletEnum values.

...

So, RET_DEFAULT < RET_NO_FTPLET < RET_SKIP > RET_DISCONNECT. If the Ftplet returns null, RET_DEFAULT is assumed.

FtpRequest

FtpSession

The session object is kept for the entire user session It provides the client request information to a ftplet. Ftplet notification methods will always get the same instance of FtpRequest for one connection. So the attributes set by setAttribute() will be always available later unless that attribute is removed. Different connections session will have different FtpRequest FtpSession objects. From here we can get user information, data streams, FTP command, argument, user file system view etc.

...

Ftplets can use this to send custom code codes and messges to clientmessages to client.

FtpRequest

Provides the client request information to a ftplet. Contains the FTP command and argument.

Ftplet

There will be only one instance of Ftplet. During startup the Ftplets will be initialized. The initialization sequence is same as the Ftplet sequence in the configuration. Then all notification methods will be called and when the FTP server goes down, the Ftplet will be destroyed. The following method describes all the notification methods.

...

Ftplet will get the Ftplet specific configuration as the init() method argument.

FtpConfig

It encapsulates the FTP server (or Ftplet container). This object is passed to Ftplet during initialization. A Ftplet can get logger, user manager, ftle system manager, server statistics information from FtpConfig.

Configuration

First of all, we have to decide a descriptive name for a Ftplet. We specify all the Ftplet names (comma separated) in config.ftplets configuration parameter. The Ftplet name must not contain any whitespace character, comma or semicolon. If we have three Ftplets (say f1, f2 and f3), the configuration will look like: config.ftplets=f1,f2,f3

The next thing is to specify the fully qualified Ftplet class name. If in the above case the class name of the Ftplet f1 is "com.example.Ftplet1" the configuration will be: config.ftplet.f1.class=com.example.Ftplet1

Similarly, you can add other Ftplet specific configuration parameters.

Implementation

Ftplets are regular POJOs. If running the server as embedded they can be added to the FtpletContainer as normal instances of the object. If using the XML configuration, they are configured and Spring beans within the ftplets element. Here's an example:

Code Block

<ftplets> 
  <ftplet name="ftplet1"> 
    <beans:bean class="org.apache.ftpserver.examples.MyFtplet"> 
No Format

              config.ftplet.f1.param1=val1
      <beans:property name="foo"       config.ftplet.f1.param2=val2value="123" /> 
    </beans:bean> 
         ....</ftplet> 
</ftplets>

Deployment

The Ftplet must be added to Apache FTP Server FtpServer classpath so that the Ftplet can be loaded. There are three ways you can do that.

  1. Modify your system CLASSPATH environment variable to include your ftplet classes.
  2. Copy your ftplet class files (unpacked) in the common/classes ubdirectory bdirectory of the FTP Server installation.
  3. Place a jar file containing the custom ftplet class files in the common/lib subdirectory of the FTP Server installation.