I. Scenarios
The project uses open source Apache ftpserver (http://mina.apache.org/ftpserver/) because it needs to support big file transfer and download ). However, to work with the client, these FTP commands cannot meet the requirements, that is, some commands need to be added, and some commands that may cause security problems to the entire system need to be deleted or modified.
Ii. Modify Apache
Ftpserver Overview
1. When a new command is added, a specific implementation class is added to inherit abstractcommand to implement the execute () method.
2. Define a class mycommandfactoryfactory, initialize default_command_map, and add custom commands.
For more information about the code, see org. Apache. ftpserver. Command. commandfactoryfactory.
3. Reset commandfactory before starting the server.
Serverfactory. setcommandfactory (New
Mycommandfactoryfactory (). createcommandfactory ());
(In addition, you can directly modify the commandfactoryfactory code, which is relatively simple. However, if you change the open-source package, we recommend that you inherit or rewrite the relevant classes, so that the packages to be updated in the future will be easier .)
Iii. How to test the customized ftpserver
For the customized ftpserver, the server cannot be tested using traditional FTP tools because the commands have changed. Therefore, you need to write a simple FTP client that is also customized for testing. The commonnet package (http://commons.apache.org/net/) provided by Apache supports the FTP protocol and is open source, so you can directly modify the code of commonnet, provide a customized version of commonnet, to support customized FTP commands. Then, use the customized version of commonnet to write a simple FTP client.
4. General idea of modifying commonnet code
1. org.apache.commons.net. FTP. ftpcommand class
It is easy to understand because there are not many codes. You need to modify or add commands.
2. org.apache.commons.net. FTP. FTP class
This class encapsulates the main functions of the FTP client. Add or modify a specific method.
3. org.apache.commons.net. FTP. ftpclient class
This class provides external services. Add or modify a specific method.
Note: because it does not involve specific services, it is not detailed enough. Sorry. The basic idea has been written out. According to this idea, it should be okay to take a closer look at the code.