Apache Mina FTP Server Events
@{45}(在版本 5.2 中添加)侦听某些 Apache Mina FTP 服务器事件,并将其发布为 @{46},任何 @{47} bean、@{48} bean 方法或 @{49} 都可以接收该事件。
The ApacheMinaFtplet
, added in version 5.2, listens for certain Apache Mina FTP server events and publishes them as ApplicationEvent
s which can be received by any ApplicationListener
bean, @EventListener
bean method, or Event Inbound Channel Adapter.
当前支持的事件有:
Currently, supported events are:
-
SessionOpenedEvent
- a client session was opened -
DirectoryCreatedEvent
- a directory was created -
FileWrittenEvent
- a file was written to -
PathMovedEvent
- a file or directory was renamed -
PathRemovedEvent
- a file or directory was removed -
SessionClosedEvent
- the client has disconnected
这些事件中的每一个都是 ApacheMinaFtpEvent
的子类;你可以配置单个监听器以接收所有事件类型。每个事件的 source
属性是一个 FtpSession
,你可以从中获取诸如客户端地址等信息;抽象事件中提供了一个方便的 getSession()
方法。
Each of these is a subclass of ApacheMinaFtpEvent
; you can configure a single listener to receive all the event types.
The source
property of each event is a FtpSession
, from which you can obtain information such as the client address; a convenient getSession()
method is provided on the abstract event.
除了会话打开/关闭之外的事件都具有另一个属性 FtpRequest
,其中包含诸如命令和自变量等属性。
Events other than session open/close have another property FtpRequest
which has properties such as the command and arguments.
若要使用监听器(它必须是一个 Spring Bean)配置服务器,请将其添加到服务器工厂:
To configure the server with the listener (which must be a Spring bean), add it to the server factory:
FtpServerFactory serverFactory = new FtpServerFactory();
...
ListenerFactory factory = new ListenerFactory();
...
serverFactory.addListener("default", factory.createListener());
serverFactory.setFtplets(new HashMap<>(Collections.singletonMap("springFtplet", apacheMinaFtpletBean)));
server = serverFactory.createServer();
server.start();
若要使用 Spring Integration 事件适配器使用这些事件:
To consume these events using a Spring Integration event adapter:
@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
ApplicationEventListeningMessageProducer producer =
new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ApacheMinaFtpEvent.class);
producer.setOutputChannel(eventChannel());
return producer;
}