Apache Mina SFTP 服务器事件
这ApacheMinaSftpEventListener
,在版本 5.2 中添加,侦听某些 Apache Mina SFTP 服务器事件并将其发布为ApplicationEvent
s 可以被任何ApplicationListener
豆@EventListener
bean 方法或 Event Inbound Channel Adapter。
目前,支持的事件包括:
-
SessionOpenedEvent
- 已打开客户端会话 -
DirectoryCreatedEvent
- 已创建目录 -
FileWrittenEvent
- 文件已写入 -
PathMovedEvent
- 文件或目录已重命名 -
PathRemovedEvent
- 文件或目录已被删除 -
SessionClosedEvent
- 客户端已断开连接
它们中的每一个都是ApacheMinaSftpEvent
;您可以配置单个侦听器来接收所有事件类型。
这source
属性是ServerSession
,您可以从中获取客户端地址等信息;一个方便的getSession()
method 在 abstract 事件上提供。
要使用侦听器(必须是 Spring bean)配置服务器,只需将其添加到SftpSubsystemFactory
:
server = SshServer.setUpDefaultServer();
...
SftpSubsystemFactory sftpFactory = new SftpSubsystemFactory();
sftpFactory.addSftpEventListener(apacheMinaSftpEventListenerBean);
...
要使用 Spring 集成事件适配器来使用这些事件:
@Bean
public ApplicationEventListeningMessageProducer eventsAdapter() {
ApplicationEventListeningMessageProducer producer =
new ApplicationEventListeningMessageProducer();
producer.setEventTypes(ApacheMinaSftpEvent.class);
producer.setOutputChannel(eventChannel());
return producer;
}