Discussion

JSCH exception Custom SFTP Error

We are trying to build a custom sftp to get a file from a remote machine and we are using pega 7.3.1 version (in Cloud) .But getting error

com.jcraft.jsch.JSchException: UnknownHostKey: xx.xx.xx.xx. RSA key fingerprint is 6a:ba:ab:12:fc:f2:bc:21:14:ae:af:bd:0c:02:ad:0d

below is the code snippet using JSCH

java.io.InputStream inputStream = null;

com.jcraft.jsch.ChannelSftp sftpChannel=null;

com.jcraft.jsch.Session ftpSession=null;

boolean isSuccess=false;

try {

com.jcraft.jsch.JSch jsch = new com.jcraft.jsch.JSch();

ftpSession = jsch.getSession(UserName,HostName,Port);

ftpSession.setPassword(Password);

ftpSession.connect();

oLog.error("Session connected ");

sftpChannel = (com.jcraft.jsch.ChannelSftp) ftpSession.openChannel("sftp");

sftpChannel.connect();

sftpChannel.put(new java.io.ByteArrayInputStream(LocalFile.getBytes()),remotePath,com.jcraft.jsch.ChannelSftp.OVERWRITE );

isSuccess=true;

}

catch (java.lang.Exception e) {

oLog.error(e.toString());

}

finally{

if (sftpChannel != null && sftpChannel.isConnected()) {

sftpChannel.disconnect();

}

if (ftpSession != null && ftpSession.isConnected()) {

ftpSession.disconnect();

}

}

return isSuccess;

***Edited by Moderator Marissa to update platform capability tags****

Comments

Keep up to date on this post and subscribe to comments

July 1, 2019 - 9:37pm

The above solution works after adding below settings even though it is not recommended

jsch.setConfig("StrictHostKeyChecking","no");