无法启动到本地apache sshd服务器(java)的ChannelSftp通道连接
我正在尝试测试到达SFTP服务器的文件。我使用以下代码设置了一个本地sshd服务器无法启动到本地apache sshd服务器(java)的ChannelSftp通道连接,java,sftp,jsch,channel,sshd,Java,Sftp,Jsch,Channel,Sshd,我正在尝试测试到达SFTP服务器的文件。我使用以下代码设置了一个本地sshd服务器 @Before public void setUp() throws Exception{ SshServer sshd = SshServer.setUpDefaultServer(); sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); sshd.setPasswordAu
@Before
public void setUp() throws Exception{
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
public boolean authenticate(String username, String password, ServerSession session) {
return true;
}
});
sshd.setPort(22);
sshd.setFileSystemFactory(new FileSystemFactory() {
@Override
public FileSystem createFileSystem(org.apache.sshd.common.session.Session session) throws IOException {
return null;
}
});
sshd.start();
}
我使用Jsch作为客户机来尝试并连接到此服务器。不幸的是,无论何时尝试调用channel.connect(),我都会遇到com.jcraft.jsch.JSchException:无法发送通道请求异常。Jsch的代码如下所示:
public void testServer(){
try{
JSch jSch = new JSch();
Session session = jSch.getSession("user", "localhost",22);
Properties configTemp = new Properties();
configTemp.put("StrictHostKeyChecking", "no");
session.setConfig(configTemp);
session.connect();
ChannelSftp channel = (ChannelSftp)session.openChannel("sftp");
channel.connect();
if(channel.isConnected()){
System.out.println("Connected");
}
}
catch (Exception e){
e.printStackTrace();
}
}
有人能帮我解决我做错了什么以及如何解决这个问题吗?谢谢您必须实施子系统工厂,如:
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
我使用的是sshdcore2.3.0,我认为这个版本中不存在这种情况。如果我使用较旧的版本,并实现子系统工厂,我会得到Session.connect:java.io.IOException:End of io Stream Read。例外