【问题标题】:how to set remotedirectory in sftp outboud gateway in java-spring integration如何在 java-spring 集成中的 sftp 出站网关中设置远程目录
【发布时间】:2023-03-08 02:05:01
【问题描述】:
<int-sftp:outbound-gateway id="sftpOutBound"
    session-factory="sftpSessionFactory"   expression="payload" command="put" request-channel="outboundFtpChannel"
    remote-directory="/tmp/tsiftp" reply-channel="sftpReplyChannel"/>

使用上面的xml,我可以发送文件并得到回复。在java中,如何在SftpOutboundGateway中设置远程目录。如果我使用SftpMessageHandler,是否有可能得到回复。注释代码正在传输文件但没有回复。

 @Bean
@ServiceActivator(inputChannel = "outboundFtpChannel")
public MessageHandler transfertoPeopleSoft(){
 /*  SftpMessageHandler handler = new SftpMessageHandler(sftpSessionFactory());
     handler.setRemoteDirectoryExpression(new LiteralExpression("/tmp/tsiftp"));
     return handler;*/
    SftpOutboundGateway sftpOutboundGateway = new  SftpOutboundGateway( sftpSessionFactory(), "put", "/tmp/tsiftp");
    sftpOutboundGateway.setOutputChannelName("sftpReplyChannel");
    return sftpOutboundGateway;
}

 Exception I am getting is
   exception is org.springframework.expression.spel.SpelParseException: Expression [/tmp/tsiftp] @0: EL1070E: Problem parsing left operand

感谢您的帮助。

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

    SftpOutboundGateway 的远程目录可以由SftpRemoteFileTemplate 及其:

    /**
     * Set the remote directory expression used to determine the remote directory to which
     * files will be sent.
     * @param remoteDirectoryExpression the remote directory expression.
     */
    public void setRemoteDirectoryExpression(Expression remoteDirectoryExpression) {
    

    https://docs.spring.io/spring-integration/docs/5.0.0.RELEASE/reference/html/sftp.html#sftp-rft

    请随时提出JIRA 以改进此事。

    我知道Expression 变体不是那么有用,因为您需要使用SpelExpressionParser 或仅使用LiteralExpression 来实现简单的 dir 变体。

    【讨论】:

    • 谢谢@artem,我会试试的。是否有任何选项可以在传输 put 命令后删除本地文件。
    • M-m-m。不,没有。您可以在SftpOutboundGateway 执行简单的File.delete() 操作后作为服务激活器执行此操作。您可以存储在邮件标头中的原始文件不会在两者之间丢失。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多