ChannelSftp获取多个文件,然后单击第二个主题的权限被拒绝

时间:2018-07-06 10:10:21

标签: java spring-integration jsch spring-integration-sftp

我试图通过以下代码获取sftp中的所有文件: 注意:我通过channel.ls("/path")获取了所有路径,然后在路径上使用ReactiveGetCommand并获取了sftp中的所有文件。

我尝试了两个命令:服务器中的mget -r <path>mget <path>/*都可以

default <T> Mono<T> usingChannel(CheckedFunction<ChannelSftp, Mono<T>> fun) {
    return Mono.using(this::newSession,
            session -> Mono.using(() -> newChannel(session), function(fun), ChannelSftp::disconnect),
            Session::disconnect);
}

default Session newSession() throws Exception {
    val jSch = new JSch();
    final Session session = jSch.getSession(getSettings().getUsername(), 
    getSettings().getHost());
    session.setPassword(getSettings().getPassphrase().getBytes(UTF_8));
    session.setConfig("StrictHostKeyChecking", "no");
    session.connect();
    return session;
}

interface ReactiveGetCommand extends ReactiveJschCommand, 
    ReactiveSftpCommand.ReactiveGetCommand {
    default Mono<Map<String, InputStream>> get(List<String> paths) {
        Objects.requireNonNull(paths, "'paths' must not be null");
        return usingChannel(channel -> Flux.fromIterable(paths)
            .flatMapDelayError(function(path -> return Mono.just(Tuples.of(path, channel.get(path)))), SMALL_BUFFER_SIZE, XS_BUFFER_SIZE).onErrorResume(e -> {
                e.printStackTrace();
                return Flux.empty();
            }).collectMap(Tuple2::getT1, Tuple2::getT2));
}
}

但是问题是:我只得到第一个项目,然后我击中下一个项目的权限被拒绝: Here is the log for the Exception

0 个答案:

没有答案