【问题标题】:SFTP Outbound Gateway CommandsSFTP 出站网关命令
【发布时间】:2020-02-24 10:52:06
【问题描述】:

我需要在SFTPOutboundGateway 中使用更多命令(cd、mkdir、rmdir),但根据the official documentation,只有少数命令可用,我需要的其他命令都没有。这背后有什么原因吗?是否有(其他)方法可以使用更多命令,例如 cd、mkdir 和 rmdir ?

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

    cd 在网关中毫无意义,因为它实际上什么都不做。

    对于网关不支持的命令,请在服务激活器中使用您的代码中的SftpRemoteFileGateway

    模板不支持的命令,使用

    /**
     * Execute the callback's doInSession method after obtaining a session.
     * Reliably closes the session when the method exits.
     *
     * @param callback the SessionCallback.
     * @param <T> The type returned by
     * {@link SessionCallback#doInSession(org.springframework.integration.file.remote.session.Session)}.
     * @return The result of the callback method.
     */
    <T> T execute(SessionCallback<F, T> callback);
    

    @FunctionalInterface 公共接口 SessionCallback {

    /**
     * Called within the context of a session.
     * Perform some operation(s) on the session. The caller will take
     * care of closing the session after this method exits.
     *
     * @param session The session.
     * @return The result of type T.
     * @throws IOException Any IOException.
     */
    T doInSession(Session<F> session) throws IOException;
    

    }

    Session 不支持的命令,使用

    /**
     * Get the underlying client library's client instance for this session.
     * Returns an {@code Object} to avoid significant changes to -file, -ftp, -sftp
     * modules, which would be required
     * if we added another generic parameter. Implementations should narrow the
     * return type.
     * @return The client instance.
     * @since 4.1
     */
    Object getClientInstance();
    
    @Override
    public ChannelSftp getClientInstance() {
        return this.channel;
    }
    

    直接在JSch客户端上操作。

    【讨论】:

    • 谢谢,我会尽量使用这些。但出于好奇,为什么 rmdir、mkdir 等无法通过 SftpOutboundGateway 获得?
    • 只是以前没有人要求他们。通常,像这样的命令将用作更大序列的一部分,而 Spring Integration 流可能不是实现这一目标的最佳方式。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多