So I use a private key to connect to the sftp server ,so it came back error:
com.jcraft.jsch.JSchException: SSH_MSG_DISCONNECT: 2 Failed to read binary packet data!
Here is the code:
JSch jsch = new JSch(); jsch.addIdentity(new File(privateKey).getAbsolutePath()); session = jsch.getSession(ftpUserName, ftpHost, ftpPort); LOGGER.debug("Session created."); if (ftpPassword != null) { session.setPassword(ftpPassword); } Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.setTimeout(timeout); session.connect();
is there anything in my code or i missed something?thank you.