Dan
Dan

Reputation: 295

SFTP Outbound Gateway Commands

I need to use more commands (cd, mkdir, rmdir) with SFTPOutboundGateway, but according to the official documentation, there is only a handful of commands available, none of the other ones I need being included. Is there a reason behind it ? Is there a(nother) way to use more commands such as cd, mkdir and rmdir ?

Upvotes: 0

Views: 297

Answers (1)

Gary Russell
Gary Russell

Reputation: 174484

cd in a gateway makes no sense since it effectively would do nothing.

For commands not supported by the gateway, use the SftpRemoteFileGateway from your code in a service activator.

For commands not supported by the template, use

/**
 * 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);

and

@FunctionalInterface public interface 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;

}

For commands not supported by Session, use

/**
 * 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;
}

and operate on the JSch client directly.

Upvotes: 1

Related Questions