在线等 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