简体   繁体   English

Spring Integration 将 SFTP 远程目录设置为 null

[英]Spring Integration is setting SFTP Remote Directory as null

I have created a tasklet to download a file at SFTP server using Spring-Integration-Batch.我创建了一个 tasklet 来使用 Spring-Integration-Batch 在 SFTP 服务器上下载文件。 While running the batch, it seems remote directory is not setting correctly in AbstractInboundFileSynchronizer because of which program is trying to synchronize null with local directory.在运行批处理时,似乎 AbstractInboundFileSynchronizer 中的远程目录设置不正确,因为哪个程序试图将 null 与本地目录同步。

When I tried calling afterPropertiesSet() of AbstractInboundFileSynchronizer just before synchronizeToLocalDirectory(), then it downloaded the files with warning as "No beanFactory".当我尝试在synchronizeToLocalDirectory()之前调用AbstractInboundFileSynchronizer的afterPropertiesSet()时,它下载了带有“No beanFactory”警告的文件。

Below is the tasklet I am running:下面是我正在运行的 tasklet:

public class FtpFileDownloadTasklet implements Tasklet {

    @Value("${ftp.source.directory}")
    private String remoteDirectory;

    @Value("${ftp.dest.directory}")
    private String localDirectory;

    @Value("${ftp.source.file.extn}")
    private String sourceFileExtn;

    @Autowired
    private SessionFactory<LsEntry> sftpSessionFactory;

    private SftpInboundFileSynchronizer fileSynchronizer;

    @Override
    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

        if (sftpSessionFactory.getSession().isOpen()) {
            fileSynchronizer = new SftpInboundFileSynchronizer(sftpSessionFactory);
            fileSynchronizer.setDeleteRemoteFiles(false);
            fileSynchronizer.setFilter(new SftpSimplePatternFileListFilter("*" + sourceFileExtn));
            fileSynchronizer.setRemoteDirectory(remoteDirectory);

            fileSynchronizer.synchronizeToLocalDirectory(new File(localDirectory));
        }

        return RepeatStatus.FINISHED;
    }
}

My Session factory:我的会话工厂:

@Bean
public SessionFactory<LsEntry> sftpSessionFactory() {
   DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory();
   factory.setHost(host);
   factory.setPort(port);
   factory.setUser(username);
   factory.setPassword(password);
   factory.setAllowUnknownKeys(true);
   return new CachingSessionFactory<LsEntry>(factory);
}

But, without a call to afterPropertiesSet(), I am getting below error:但是,如果没有调用 afterPropertiesSet(),就会出现以下错误:

org.springframework.messaging.MessagingException: Problem occurred while synchronizing 'null' to local directory; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to list files; nested exception is 4: 
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:315) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:293) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at com.ftp.demo.tasklet.FtpFileDownloadTasklet.execute(FtpFileDownloadTasklet.java:52) ~[classes/:na]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:203) ~[spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:399) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:313) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:144) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137) [spring-batch-core-4.1.2.RELEASE.jar:4.1.2.RELEASE]
    at com.ftp.demo.main.SpringBatchIntegrationftpDemoApplication.main(SpringBatchIntegrationftpDemoApplication.java:44) [classes/:na]
Caused by: org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to list files; nested exception is 4: 
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:446) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.synchronizeToLocalDirectory(AbstractInboundFileSynchronizer.java:308) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    ... 20 common frames omitted
Caused by: org.springframework.core.NestedIOException: Failed to list files; nested exception is 4: 
    at org.springframework.integration.sftp.session.SftpSession.list(SftpSession.java:103) ~[spring-integration-sftp-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.sftp.session.SftpSession.list(SftpSession.java:50) ~[spring-integration-sftp-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession.list(CachingSessionFactory.java:230) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.transferFilesFromRemoteToLocal(AbstractInboundFileSynchronizer.java:323) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.lambda$synchronizeToLocalDirectory$0(AbstractInboundFileSynchronizer.java:309) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:437) ~[spring-integration-file-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    ... 21 common frames omitted
Caused by: com.jcraft.jsch.SftpException: 
    at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1747) ~[jsch-0.1.55.jar:na]
    at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1553) ~[jsch-0.1.55.jar:na]
    at org.springframework.integration.sftp.session.SftpSession.list(SftpSession.java:91) ~[spring-integration-sftp-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    ... 26 common frames omitted
Caused by: java.lang.NullPointerException: null
    at com.jcraft.jsch.ChannelSftp.remoteAbsolutePath(ChannelSftp.java:2943) ~[jsch-0.1.55.jar:na]
    at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1572) ~[jsch-0.1.55.jar:na]
    ... 28 common frames omitted

In the execute method instead of在执行方法中而不是

fileSynchronizer.synchronizeToLocalDirectory(new File(localDirectory));
    }
Use 


fileSynchronizer.setFilter(
    new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "rotate")
);

It will sync your local directory with a remote file.它会将您的本地目录与远程文件同步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring 集成 SFTP 按需删除远程文件 - Spring Integration SFTP Delete Remote File On Demand 将文件/文件从远程目录移动到另一个 Spring 集成 SFTP 出站网关 Java 配置/Java DSL - Moving file/files from remote directory to another Spring Integration SFTP Outbound Gateway Java Config/Java DSL 设置Spring Integration SFTP的连接超时 - Setting connection timeout for Spring Integration SFTP 在Spring Integration中通过sftp移动目录 - Move directory via sftp in spring integration 设置 Spring Integration SFTP 出站网关时出现 UnsatisfiedDependencyException - UnsatisfiedDependencyException when setting up a Spring Integration SFTP outbound gateway 如何使用 spring 集成和 sftp 将文件从一个目录移动到另一个目录 - How to move file from directory to another with spring integration and sftp Spring Integration Java DSL SFTP如何在处理程序中获取远程SFTP服务器信息 - Spring Integration Java DSL SFTP how to get remote SFTP server information in handler spring sftp在没有本地目录的远程读写 - spring sftp read and write in remote without local directory 如何使用 spring 与 sftp 集成上传和下载目录及其子目录 - How to upload and download a directory along with sub directory using spring integration with sftp 春季集成:带有SFTP网关的Http - Spring Integration: Http with SFTP Gateway
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM