跳到主要内容
版本:7.0.2

Apache Mina FTP 服务器事件

DeepSeek V3 中英对照 Apache Mina FTP Server Events

ApacheMinaFtplet 自 5.2 版本起引入,用于监听特定的 Apache Mina FTP 服务器事件,并将这些事件作为 ApplicationEvent 发布。任何 ApplicationListener Bean、@EventListener Bean 方法或事件入站通道适配器均可接收这些事件。

目前支持的事件有:

  • SessionOpenedEvent - 客户端会话已开启

  • DirectoryCreatedEvent - 目录已创建

  • FileWrittenEvent - 文件已写入

  • PathMovedEvent - 文件或目录已重命名

  • PathRemovedEvent - 文件或目录已移除

  • SessionClosedEvent - 客户端已断开连接

这些事件都是 ApacheMinaFtpEvent 的子类;你可以配置一个监听器来接收所有事件类型。每个事件的 source 属性都是一个 FtpSession,你可以从中获取诸如客户端地址等信息;抽象事件上提供了一个便捷的 getSession() 方法。

除了会话打开/关闭事件外,其他事件还包含另一个属性 FtpRequest,该属性具有诸如命令和参数等属性。

要配置服务器监听器(必须是一个 Spring bean),请将其添加到服务器工厂中:

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 事件适配器来消费这些事件:

@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
ApplicationEventListeningMessageProducer producer =
new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ApacheMinaFtpEvent.class);
producer.setOutputChannel(eventChannel());
return producer;
}