当前位置: 首页 > 知识库问答 >
问题:

Spring集成-列出通过RemoteFileTemplate下载的文件名

毋城
2023-03-14

我正在使用Spring集成RemoteFileTemplate通过Sftp下载文件。如何对正在下载的每个文件名执行一些处理?我看到那条线

.log(logginghandler.level.info,“sftp.inbound”,message::getheaders)

记录文件名,但我需要直接可用的文件名。

我需要做的只是将下载的文件名作为列表写入POJO中,以便作为响应传递给稍后的进程。我的代码附在下面。

`@Configuration@EnableIntegration公共类SftpInboundFlowIntegrationConfig{private static final Logger log=LoggerFactory.getLogger(SftpInboundFlowIntegrationConfig.class);private String sftpRemoteDirectory=“/”;

@Bean
public SessionFactory<ChannelSftp.LsEntry> inboundSftpSessionFactory() {
    DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
    factory.setHost("localhost");
    factory.setPort(2222);
    factory.setUser("local");
    factory.setPassword("local");
    factory.setAllowUnknownKeys(true);
    return new CachingSessionFactory<>(factory);
}

@Bean
public IntegrationFlow sftpInboundFlow(RemoteFileTemplate<ChannelSftp.LsEntry> 
inboundRemoteFileTemplate) {
    return e -> e
            .log(LoggingHandler.Level.INFO, "sftp.inbound", Message::getPayload)
            .log(LoggingHandler.Level.INFO, "sftp.inbound", Message::getHeaders)
            .handle(
                    Sftp.outboundGateway(inboundRemoteFileTemplate, AbstractRemoteFileOutboundGateway.Command.MGET, "payload")
                            .localDirectory(new File("c:/tmp"))
            );
}

@Bean
public RemoteFileTemplate<ChannelSftp.LsEntry> inboundRemoteFileTemplate(SessionFactory<ChannelSftp.LsEntry> inboundSftpSessionFactory) {
    RemoteFileTemplate<ChannelSftp.LsEntry> template = new SftpRemoteFileTemplate(inboundSftpSessionFactory);
    template.setRemoteDirectoryExpression(new LiteralExpression(sftpRemoteDirectory));
    template.setAutoCreateDirectory(true);
    template.afterPropertiesSet();
    template.setUseTemporaryFileName(false);
    return template;
}
}

共有1个答案

贝财
2023-03-14

对不起大家。我试图在错误的代码区域完成此操作。我意识到,当我调用出站网关下载文件时,SftpOutBoundGateway.mget(“/”);它返回下载的文件列表,这正是我所需要的。

 类似资料:
  • 问题内容: 我在服务器端有一个Struts2操作,用于文件下载。 但是,当我使用jQuery调用操作时: 在Firebug中,我看到数据是通过 Binary流 检索的。我想知道如何打开 文件下载窗口 ,用户可以用它在本地保存文件吗? 问题答案: 这是我现在建议的一些注意事项: 需要相对较新的浏览器 如果预期文件 很大,则 您可能应该执行与原始方法(iframe和cookie)类似的操作,因为以下某

  • 我试图使简单的文件服务器。我有Node.js后端与MongoDB GridFS存储存储文件。我从服务器获取文件通过。在前端,我使用Angular。我有两个主要问题: 当我使用Blob提供下载服务时,变成:“d1c393df-b0d9-4ae5-befe-8d45b183eb54…”友善的我读了很多关于它的文档,没有找到任何解决方案 当我只通过Express提供下载服务而不进行身份验证时,文件会正确

  • 下面是Java样例代码 import java.io.IOException; import com.xiaomi.infra.galaxy.fds.client.FDSClientConfiguration; import com.xiaomi.infra.galaxy.fds.client.GalaxyFDS; import com.xiaomi.infra.galaxy.fds.clien

  • 有人成功地从linux终端下载了wetransfer链接吗? thnx mart

  • 我在Spring Boot应用程序中使用Spring集成版本5.4.4。我需要从“server_sftp”目录下的子目录中获取所有的XML文件。为此,我使用带有mget命令的SFTP流入站通道适配器和SFTP出站网关。不幸的是,应用程序只从根目录(server_sftp)下载文件,而不从子目录下载文件。 我哪里出错了? sftp服务器上的目录结构

  • 问题内容: 我正在构建一个应用程序,以从后端服务器下载PDF文件。我写了以下代码: 在后端服务器上,方法如下: 我从我的适配器调用此rest方法为: 通话结束后,我从此服务获得以下响应: 如何解析此响应为PDF文件并将其显示给用户?当我使用以下代码从应用程序中简单地调用此适配器方法时,当我右键单击适配器并选择运行为“调用移动适配器”时,也会收到此响应: 我在浏览器的控制台上得到了相同的响应,但是正