Its IoC based architecture allows for extending or customizing the Hermes FTP Server easily. Moreover, if you need to embed the ftp server in your own application you certainly can do so. The following paragraphs describe both of the scenarios.
Open the application context hermesftp-ctx.xml and find the parser bean. Now add the highlighted line to the list of properties:
<bean id="parser" singleton="true" class="net.sf.hermesftp.parser.impl.FtpCmdParserImpl"> <property name="commands"> <map> ... <entry key="SITE" value="cmdSite" /> ... </map> </property> </bean>
Add a new bean to the application context and name it cmdSite.
<bean id="cmdSite" class="example.FtpCmdSite" singleton="false" />
Now open your IDE (if not already done) and extend the class net.sf.hermesftp.cmd.AbstractFtpCmd as outlined in the snippet below.
package example; import net.sf.hermesftp.cmd.AbstractFtpCmd; import net.sf.hermesftp.exception.FtpCmdException; public class FtpCmdSite extends AbstractFtpCmd { /** * {@inheritDoc} */ public void execute() throws FtpCmdException { // handle command if (ok) { msgOut(MSG200_NOTED); } else { msgOut(MSG500; } } /** * {@inheritDoc} */ public String getHelp() { return "My custom site command."; } /** * {@inheritDoc} */ public boolean isAuthenticationRequired() { return true; }
After wrapping the compiled class into a JAR file you must copy the archive into the folder $HERMES_HOME/plugins. All classes found in this folder are loaded automatically after starting up the application. In the same way all parts of Hermes FTP Server represented by a Spring bean can be replaced.
private void startServer(String beanRes) throws FtpException { ApplicationContext appContext = new FileSystemXmlApplicationContextEx (new String[] {beanRes}); FtpServer svr = (FtpServer) appContext.getBean( BeanConstants.BEAN_SERVER); Thread svrThread = new Thread(svr); svrThread.start(); }