0

I am using Jsch Library for SFTP. From My terminal, I have done ssh to the ftp machine, to add the ftp machine into known_host file. But when I am connecting to SFTP machine from Java using Jsch, it is not able to find out the host, also the ECDSA key fingerprint shown for the host in Java and in Terminal are different.

But I am not facing any issue in connecting to same host from python using pysftp.

If the host ip is same, why is Jsch getting a different signature ?

I have redacted hostname for security purpose. I have done sftp from terminal and added to known hosts. From Terminal, Added it to known_hosts

here is the snippet of java code, which I am using to connect to sftp.

String host = platformDetailMap.get(Constants.SFTPProps.HOST);
            String username = platformDetailMap.get(Constants.SFTPProps.USERNAME);
            String password = platformDetailMap.get(Constants.SFTPProps.PASSWORD);

            JSch ssh = new JSch();
            Session session = null;
            Channel channel = null;
            try {
                session = ssh.getSession(username, host, SFTP_PORT);
                session.setPassword(password);
//                java.util.Properties config = new java.util.Properties();
//                config.put("StrictHostKeyChecking", "no");
//                session.setConfig(config);
                session.connect();
                channel = session.openChannel(SFTP_CHANNEL_IDENTIFIER);
                channel.connect();
                ChannelSftp sftp = (ChannelSftp) channel;
                List<SFTPFile> fileList = new ArrayList<SFTPFile>();
                Vector<ChannelSftp.LsEntry> entryList = sftp.ls(path);

This is producing the following exception.

In Eclipse when trying to connect to the same host

saiki4116
  • 323
  • 1
  • 4
  • 14
  • Show us your code + JSch log file + `known_hosts` file + `ssh` command-line that you are using + FTP and SFTP are two completely different protocol, do not mix them. + Where do you execute the `ssh`? Is it the same machine as you are running your JSch code at? – Martin Prikryl Jun 28 '17 at 16:37
  • @MartinPrikryl , when I did sftp username@host, it didn't ask to add to known_hosts file. I did ssh username@host, and have added to the known_hosts file. – saiki4116 Jun 29 '17 at 18:04
  • @MartinPrikryl, tried with sftp command also, same happens. – saiki4116 Jun 29 '17 at 18:31

0 Answers0