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 FtpServer notifications. Apache FtpServer is a Ftplet container, allowing administrators to deploy Ftplet to carry out a variety of complex FTP event handler tasks.

...

  • RET_DEFAULT : This return value indicates that the next ftplet method will be called. If no other ftplet is available, the FTP server FtpServer will process the request.
  • RET_NO_FTPLET : This return value indicates that the other ftplet methods will not be called but the FTP server FtpServer will continue processing this request.
  • RET_SKIP : It indicates that the FTP server will skip everything. No further processing (both ftplet and server) will be done for this request (besides called afterCommand is RET_SKIP is returned before the command invocation).
  • RET_DISCONNECT : It indicates that the server will skip and disconnect the client. No other request from the same client will be served.

...

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 FtpServer goes down, the Ftplet will be destroyed. The following method describes all the notification methods.

Method

Description

onConnect

Client connect notification method. This is the first method FTP server FtpServer will call. If it returns RET_SKIP, IP restriction check, connection limit check will not be performed and the server will not send the welcome message (220).

onDisconnect

Client disconnect notification method. This is the last method FTP server FtpServer will call. Whatever it returns, the client connection will be closed.

beforeCommand

Called before the server invoke the command.

afterCommand

Called after the server as invoked the command.

DefaultFtplet

DefaultFtplet provides some convenience methods for common FTP commands. Users can easily extend the DefaultFtplet class and choose what methods to override and handle.

Method

Description

onLogin

Client login notification method. This will be called after the user authentication. In this case the FTP server FtpServer has already sent the login OK (230) reply. This is called during FTP PASS request. The FTP session will be disconnected in the return value is FtpletEnum.RET_DISCONNECT.

onDeleteStart

Before file deletion this method will be called. Before this FTP server FtpServer will not check anything like file existance existence or permission. The requested file name can be get from request argument. We can get the file object from the request file system view. This is called in DELE FTP command. The method should send some responses (like 250, 450, 550) in case of RET_SKIP return value. In this case, the server will skip the command processing and the ftplet has to send appropriate response values.

onDeleteEnd

This method will be called if after the file deletion is , successful or not. In this case the FTP server FtpServer has already sent the command OK (250) message. If onDeleteStart() method returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP serverreply message. This is called in DELE FTP command.

onUploadStart

This method will be called before the file upload. The file name can be get from the request argument. We can get the data input stream from request. This will be called before the permission check. This is called during STOR command. If the method returns RET_SKIP, it has to send responses before and after processing. For example, before opening the data input stream, the method has to notify the client with a response code 150. Similarly, after the data transfer, the method has to notify the client with a response code 226. In case of any error, the method should send different response codes like 450, 425, 426, 551.

onUploadEnd

This notification method will be called to indicate that the file transfer is successful and the server has send the replies. In case of any error this method will not be called. If onUploadStart() eturns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP server. This is called in STOR command.

onDownloadStart

This is file download request notification method called during RETR command. This will be called before the file download. We can get the file name argument from request. Similarly, the data output stream can be get from the request. This will be called before the file existance and permissoin check. If the method returns RET_SKIP, it has to send responses before and after processing. For example, before opening the data output stream, the method has to notify the client with a response code 150. Similarly, after the data transfer, the method has to notify the client with a response code 226. In case of any error, the method should send different response codes like 450, 425, 426, 551.

onDownloadEnd

This notification method will be called to indicate that the file transfer is successful and the server has send the replies in RETR command. In case of any error this method will not be called. If onDownloadStart() returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP server.

onRmdirStart

Before directory deletion this method will be called during RMD command. Before this FTP server FtpServer will not check anything like directory existance or permission. The requested directory name can be get from request argument. If the method returns the RET_SKIP, it has to send appropriate response codes to clients like 250, 450, 550.

onRmdirEnd

This method will be called if the directory deletion is successful in after the invocation of the RMD command. In this case the FTP server FtpServer has already sent the command OK (250) message. If onRmdirStart() method returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP serverreply message.

onMkdirStart

Before directory creation this method will be called during MKD command. Before this FTP server FtpServer will not check anything like directory existance or permission. The requested directory name can be get from request argument. If it returns RET_SKIP, it has to send appropriate response codes to clients like 250, 550.

onMkdirEnd

This method will be called if the directory creation is successful in MKD command. In this case the FTP server FtpServer has already sent the command OK (250) message. If onMkdirStart() method returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP serverreply message.

onAppendStart

This is file append request notification method called in APPE command. The file name can be get from the request argument. We can get the data input stream from request. This will be called before the permission check. If the method returns RET_SKIP, it has to send responses before and after processing. For example, before opening the data input stream, the method has to notify the client with a response code 150. Similarly, after the data transfer, the method has to notify the client with a response code 226. In case of any error, the method should send different response codes like 450, 425, 426, 551.

onAppendEnd

This is file append success notification method called in APPE command. This notification method will be called to indicate that the file transfer is successful and the server has send the replies. In case of any error this method will not be called. If onAppendStart() returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP server.

onUploadUniqueStart

This is unique file create request notification method called in STOU command. We can get the data input stream from request. This will be called before the permission check. If the method returns RET_SKIP, it has to send responses before and after processing. For example, before opening the data input stream, the method has to notify the client with a response code 150. Similarly, after the data transfer, the method has to notify the client with a response code 226. In case of any error, the method should send different response codes like 450, 425, 426, 551.

onUploadUniqueEnd

This is unique file create success notification method called in STOU command. This notification method will be called to indicate that the file transfer is successful and the server has send the replies. In case of any error this method will not be called. If onUploadUniqueStart() returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP Server.

onRenameStart

This is file rename start notification method called in RNTO command. This will be called before the file existance or permission check. The "rename from" file object can be get from request object. If it returns RET_SKIP, it has to send appropriate response codes like 503, 553, 250.

onRenameEnd

This is file rename success notification method called in RNFR command. This will be called before the file existance or permission check. The "rename from" file object an be get from request object. This notification method will be called to indicate that the file rename is successful after the invocation of the RNTO command and the server has send the success reply (250). In case of any error this method will not be called. If onRenameStart() returns RET_SKIP or RET_DISCONNECT, this method will not be called by the FTP Serverreply message.

onSite

This is SITE command start notification method. It gives a chance to implement custom SITE command. If this method returns RET_SKIP or RET_DISCONNECT, the existing SITE commands will not be executed.

...

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