猿问

列出远程服务器目录中的文件名

我想递归地列出远程目录及其子目录中的文件。我知道可以通过调用 ListGateway 的 listFiles 方法来做到这一点:


列表列表 = listGateway.listFiles("/ussama/providers")


@MessagingGateway

public interface ListGateway {


    @Gateway(requestChannel = "listSftpChannel")

    List<File> listFiles(String dir);


}


@Bean

@ServiceActivator(inputChannel = "listSftpChannel")

public MessageHandler handler() {

    SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "ls", "'/directory'");

    return  sftpOutboundGateway;

}


@Bean

public IntegrationFlow sftpOutboundListFlow() {

    return IntegrationFlows.from("listSftpChannel")

            .handle(new SftpOutboundGateway(sftpSessionFactory(), "ls", "payload")

            ).get();

}

但我想每隔 x 分钟做一次。有没有办法可以轮询远程目录以在每 x 分钟后列出文件。请给java配置。


Smart猫小萌
浏览 184回答 1
1回答

紫衣仙女

轮询目录的简单 POJO 消息源并根据需要配置轮询器...@Beanpublic IntegrationFlow pollLs(SessionFactory<LsEntry> sessionFactory) {&nbsp; &nbsp; return IntegrationFlows.from(() -> "foo/bar", e -> e&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .poller(Pollers.fixedDelay(5, TimeUnit.SECONDS)))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .handle(Sftp.outboundGateway(sessionFactory, Command.LS, "payload")&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .options(Option.RECURSIVE))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .handle(System.out::println)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .get();}显然,您将需要一些服务.handle来接收List<LsEntry>结果。顺便说一句,有一个工厂类Sftp可以方便地创建端点。
随时随地看视频慕课网APP

相关分类

Java
我要回答