【发布时间】:2019-07-10 16:25:47
【问题描述】:
我一直在使用 JSch 与 OpenSSH 服务器建立 SFTP 连接,在此过程中,当我尝试以 URI 的形式将私钥添加为身份时,无法识别私钥。
当我尝试从浏览器运行 URL 时,它运行正常。
我已经尝试了所有使用转义字符的方法,但没有奏效。
Session session = null;
ChannelSftp channelSftp = null;
log.info(file.getOriginalFilename());
log.info(privatekey);
JSch jsch = new JSch();
jsch.addIdentity(this.privatekey);
log.info("identity added ");
session = jsch.getSession(username,hostname,portno);
log.info("Session Created");
session.setPassword(password);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(60000);
session.connect();
log.info("session connected.....");
channelSftp = (ChannelSftp) session.openChannel("sftp");
log.info("Channel Opened.....");
log.info(channelSftp.toString());
channelSftp.setInputStream(System.in);
channelSftp.setOutputStream(System.out);
channelSftp.connect();
log.info("Channel connected.....");
//channelSftp.cd(destination);
log.info(file.getOriginalFilename());
channelSftp.put(file.getInputStream(), file.getOriginalFilename(), ChannelSftp.OVERWRITE);
channelSftp.put(file.getInputStream(),file.getOriginalFilename());
channelSftp.disconnect();
session.disconnect();
我希望必须使用 add identity 添加密钥,但不幸的是我收到以下错误
[https-jsse-nio-10443-exec-10] c.d.a.l.r.s.BlkCounterpartyServiceImpl:遇到的错误是:com.jcraft.jsch.JSchException:java.io.FileNotFoundException:http://staging.fileserver.com/properties/xyz/ xyz/xyz.ppk(没有这样的文件或目录)。
该文件位于此位置http://staging.fileserver.com/properties/xyz/xyz/xyz.ppk
【问题讨论】:
标签: java ssh jsch private-key