我想要为传输文件模拟ssh服务器。为此,我使用Apache Mina SSHD。对于系统中的转移使用JSch。私钥。
JSch客户端代码。
JSch jSch = new JSch();
jSch.addIdentity(privateKeyPath, passPhrase);
Session session = jSch.getSession(usernamePlans, remoteHost);
session.setHost(remoteHostPort);
config.setProperty("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setUserInfo(new StorageUserInfo(passPhrase));
session.connect();
Apache Mina SSHD代码
sshd = SshServer.setUpDefaultServer();
sshd.setPort(22999);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(privateKeyPath));
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String username, String password, ServerSession session) {
// TODO Auto-generated method stub
return true;
}
});
CommandFactory myCommandFactory = new CommandFactory() {
public Command createCommand(String command) {
System.out.println("Command: " + command);
return null;
}
};
sshd.setCommandFactory(new ScpCommandFactory(myCommandFactory));
List<NamedFactory<Command>> namedFactoryList = new ArrayList<>();
namedFactoryList.add(new SftpSubsystem.Factory());
sshd.setSubsystemFactories(namedFactoryList);
sshd.start();
有人可以帮我连接JSch和Apache Mina SSHD以获取传输文件吗?
栈跟踪
com.jcraft.jsch.JSchException: java.net.SocketException: Invalid argument or cannot assign requested address
Caused by: java.net.SocketException: Invalid argument or cannot assign requested address