java sftp mget_关于 spring 集成sftp的讨论

我使用 spring integration sftp下载和上传文件 . 在文档中,我找到了

Spring Integration通过提供三个客户端 endpoints 支持通过SFTP发送和接收文件:入站通道适配器,出站通道适配器和出站网关

当我想下载文件时,我必须分配本地目录,当我想上传文件时,我必须分配远程目录 . 但是如果我在编写代码时无法分配目录,例如我的目录与date.How关联 . 我可以在运行时分配目录吗?

这是我的代码:

@Bean

public SessionFactory sftpSessionFactory(){

DefaultSftpSessionFactory defaultSftpSessionFactory = new DefaultSftpSessionFactory();

defaultSftpSessionFactory.setHost(host);

defaultSftpSessionFactory.setPort(Integer.parseInt(port));

defaultSftpSessionFactory.setUser(username);

defaultSftpSessionFactory.setPassword(password);

defaultSftpSessionFactory.setAllowUnknownKeys(true);

return new CachingSessionFactory(defaultSftpSessionFactory);

}

@Bean

public SftpRemoteFileTemplate sftpRemoteFileTemplate(){

SftpRemoteFileTemplate sftpRemoteFileTemplate = new SftpRemoteFileTemplate(sftpSessionFactory());

return sftpRemoteFileTemplate;

}

@Bean

@ServiceActivator(inputChannel = "sftpChannel")

public MessageHandler handlerGet() {

SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "mget", "payload");

sftpOutboundGateway.setLocalDirectory(new File(localDirectory));

sftpOutboundGateway.setFilter(new SftpSimplePatternFileListFilter("*.txt"));

sftpOutboundGateway.setSendTimeout(1000);

return sftpOutboundGateway;

}

在messageHandler中,我必须在outboundGateway中分配localDirectory . 当我想要更改我的localDirectory几天 . 我必须将文件下载到localDirectory并移动到目标目录 . 如何在运行时分配localDirectory . 今天我下载到20170606 /明天我下载到20170607?

编辑

这是我的选择和测试

public interface OutboundGatewayOption {

@Gateway(requestChannel = "sftpChannel")

public List getFiles(String dir);

}

@Test

public void test2(){

outboundGatewayOption.getFiles("upload/20160920/");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值