Apache Mina SFTP Server Events

在版本 5.2 中添加的 ApacheMinaSftpEventListener,侦听特定的 Apache Mina SFTP 服务器事件,并将它们发布为 ApplicationEvent,任何 ApplicationListener Bean、@EventListener Bean 方法或 Event Inbound Channel Adapter 都可以接收这些事件。

The ApacheMinaSftpEventListener, added in version 5.2, listens for certain Apache Mina SFTP 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

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

Each of these is a subclass of ApacheMinaSftpEvent; you can configure a single listener to receive all the event types. The source property of each event is a ServerSession, from which you can obtain information such as the client address; a convenient getSession() method is provided on the abstract event.

要使用侦听器配置服务器(该侦听器必须是 Spring bean),只需将其添加到 SftpSubsystemFactory

To configure the server with the listener (which must be a Spring bean), simply add it to the SftpSubsystemFactory:

server = SshServer.setUpDefaultServer();
...
SftpSubsystemFactory sftpFactory = new SftpSubsystemFactory();
sftpFactory.addSftpEventListener(apacheMinaSftpEventListenerBean);
...

若要使用 Spring Integration 事件适配器使用这些事件:

To consume these events using a Spring Integration event adapter:

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