我使用jsch从java连接sftp服务器,并将文件发送到特定的目录。
private static boolean enviarCSV(String localFile) throws IOException, JSchException, SftpException {
logger.info("Enviando fichero a maquina destino..");
ChannelSftp channelSftp = setupJsch();
channelSftp.connect();
String remoteDir = Config.getParametro("wssf.conf.remoteDir");
channelSftp.put(localFile, remoteDir + localFile);
logger.info("Enviado con exito!");
channelSftp.exit();
return false;
}
private static ChannelSftp setupJsch() throws JSchException {
JSch jsch = new JSch();
String user = Config.getParametro("wssf.conf.login.usuario");
String password = Config.getParametro("wssf.conf.login.password");
String remoteHost = Config.getParametro("wssf.conf.remotehost");
Session jschSession = jsch.getSession(user, remoteHost, 40020);
jschSession.setConfig("StrictHostKeyChecking", "no");
jschSession.setPassword(password);
jschSession.connect();
return (ChannelSftp) jschSession.openChannel("sftp");
}我需要使用公钥来连接SFTP服务器。我在安全方面是个新手,我不确定该怎么做,另外,我只看到使用私钥的例子,但我想我不需要它,不是吗?
如果你能帮我,我将不胜感激
发布于 2020-06-17 17:46:35
密钥成对出现。一个是私人的,一个是公共的。
要使用您的公钥(您自由共享)进行身份验证,您需要向另一方证明您实际上也拥有匹配的私钥(因为任何人都可以拥有您的公钥,但只有您拥有私钥)。
你可以用你的私钥加密或演唱一些东西--这可以通过你的公钥来验证。
因此,对于“公钥身份验证”,您实际上也必须使用私钥...并且可以使用参考的示例:-)
https://stackoverflow.com/questions/62425581
复制相似问题