Команды исходящего шлюза SFTP - PullRequest
0 голосов
/ 24 февраля 2020

Мне нужно использовать больше команд (cd, mkdir, rmdir) с SFTPOutboundGateway, но согласно официальной документации , есть только несколько доступных команд, ни одна из других мне не нужна будучи включенным Есть ли причина этого? Есть ли (другой) способ использовать больше команд, таких как cd, mkdir и rmdir?

1 Ответ

1 голос
/ 24 февраля 2020

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 publi c 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;

}

Для команд, не поддерживаемых 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 напрямую.

...