解释:
我正在为我的同事构建一个测试工具。我有几个“模拟”内存后端,他们需要使用它们来运行集成测试。
因此,我需要运行能够上传/下载文件的 SSH 服务器。
基本用例如下:
- 上传文件,通过 Apache Camel 路由下载文件
- 上传文件,通过 Apache Camel 路由将文件传输到不同的文件夹,下载文件以验证转换,内容
问题:
我编写了 Apache SSHD 服务器:
服务器实现示例SshServer.java
:
package com.example.sshd;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.scp.ScpCommandFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.nio.file.Files;
public class SSHServer {
private SshServer sshServer;
private static final Logger logger = LoggerFactory.getLogger(SSHServer.class);
public SSHServer() throws IOException {
sshServer = SshServer.setUpDefaultServer();
sshServer.setHost("127.0.0.1");
sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Files.createTempFile("host_file", ".ser").toAbsolutePath()));
sshServer.setCommandFactory(new ScpCommandFactory());
sshServer.setPasswordAuthenticator((username, password, serverSession) -> {
logger.debug("authenticating: {} password: {}", username, password);
return username != null && "changeit".equals(password);
});
}
public void startServer() throws IOException{
sshServer.start();
}
public void stopServer() throws IOException {
sshServer.stop();
}
}
我试过了:
- 查找 JavaDoc
- 在 StackOverflow 上找到类似的问题/解决方案
- 阅读 GitHub 上的 Apache SSHD 文档
到目前为止我找不到答案。我找到了这篇文章,看起来我也需要 SSH 客户端。我在正确的轨道上吗?
- 我需要 SSH 客户端将文件写入 SSH 服务器吗?
- 如何在运行 Apache SSHD 服务器时写入文件?