V5.2 中添加的 ,侦听某些 Apache Mina FTP 服务器事件,并将它们发布为 s,任何 bean、bean 方法或事件入站通道适配器都可以接收这些事件。ApacheMinaFtpletApplicationEventApplicationListener@EventListener

目前,支持的事件包括:

  • SessionOpenedEvent- 客户端会话已打开

  • DirectoryCreatedEvent- 已创建目录

  • FileWrittenEvent- 一个文件被写入

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

  • PathRemovedEvent- 文件或目录被删除

  • SessionClosedEvent- 客户端已断开连接

它们中的每一个都是 的子类;您可以配置单个侦听器来接收所有事件类型。 每个事件的属性是 ,从中可以获取客户端地址等信息;在抽象事件上提供了一种方便的方法。ApacheMinaFtpEventsourceFtpSessiongetSession()

会话打开/关闭以外的事件具有另一个属性,该属性具有命令和参数等属性。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;
}