How to add or modify FTP commands Based on Apache ftpserver

Source: Internet
Author: User
Tags ftp commands ftp protocol

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.