如何使用SFTP出站网关命令下载文件? [英] how to use SFTP Outbound Gateway 'mget' command to download files?
本文介绍了如何使用SFTP出站网关命令下载文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Bean
public SessionFactory<ChannelSftp.LsEntry> sftpSessionFactory() {
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(true);
....
return new CachingSessionFactory<>(factory);
}
@Bean(name = "lsGateway")
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handlerLs() {
// call 'mget' command to download all the files in server folder
SftpOutboundGateway sftpOutboundGateway = new SftpOutboundGateway(sftpSessionFactory(), "mget", "payload");
sftpOutboundGateway.setLocalDirectory(new File("/local/path"));
return sftpOutboundGateway;
}
网关接口:
@MessagingGateway
public interface OutboundGatewayOption {
@Gateway(requestChannel = "sftpChannel")
List<File> mget(String dir);
}
执行下载:
@Component
public class Step1Tasklet implements Tasklet {
@Autowired
private OutboundGatewayOption gatewayOption;
@Override
public RepeatStatus execute(StepContribution stepContribution,
ChunkContext chunkContext) throws Exception {
// download files in server folder
List<File> files = gatewayOption.mget("/ftp/server/path/");
return RepeatStatus.FINISHED;
}
}
我遇到此异常:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sftpChannel' available
我在谷歌上搜索了一下,但找不到这个问题,有谁能帮帮忙吗?
推荐答案
没有名为"sftpChannel"的Bean
表示您还没有sftpChannel
MessageChannel
bean。
我认为问题来自@MessagingGateway
bean定义。
sftpChannel
bean:
@Bean
public MessageChannel sftpChannel() {
return new DirectChannel();
}
对,在最新的Spring集成中,此问题已得到解决,并且MessageChannel
最近按需从其名称解决。
这篇关于如何使用SFTP出站网关命令下载文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文