在线等 SFTP:java.security.spec.InvalidKeySpecException

pjj 2012-08-11 06:56:22
对方服务器是用户名密码认证
可是用 jsch 类包连接对方时总是报下面的错误,请高手指教
com.jcraft.jsch.JSchException: Session.connect: java.security.spec.InvalidKeySpecException: Unknown key spec.

public ChannelSftp connect(String host, int port, String username,
String password) {
ChannelSftp sftp = null;
try {
JSch jsch = new JSch();
jsch.getSession(username, host, port);
Session sshSession = jsch.getSession(username, host, port);
System.out.println("Session created.");
sshSession.setPassword(password);
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "ask");
sshSession.setConfig(sshConfig);
sshSession.connect();
System.out.println("Session connected.");
System.out.println("Opening Channel.");
Channel channel = sshSession.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;
System.out.println("Connected to " + host + ".");
} catch (Exception e) {
System.out.println(e.toString());
}
return sftp;
}
代码也是CSDN上下载的
类包版本 jsch-0.1.44
...全文
446 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧