0

I am trying to connect to an SFTP server that I created using Docker. When I connect via FileZilla everything is fine.

FileZilla connect

logs: logs after connecting from FileZilla:

 Accepted password for user from 000.00.0.0 port 54200 ssh2

However, when I try to use the JSch library through Jave, it gives me the error com.jcraft.jsch.JSchException: Algorithm negotiation fail ]. It looks like it might be an ssh key problem, but I've disabled JSch.setConfig authorship ("StrictHostKeyChecking", "no"); I tried to use other libraries, still the same. Each tip will be valuable :)


    @SneakyThrows
    public void upload() {
        ChannelSftp channelSftp = setupJsch();
        channelSftp.connect();
        String localFile = "/home/user/sftp/src/main/resources/text.txt";
        String remoteDir = "/upload/";
        channelSftp.put(localFile, remoteDir + "testFile.txt");
        channelSftp.exit();

    }

    @SneakyThrows
    public ChannelSftp setupJsch() {
        JSch.setConfig("StrictHostKeyChecking", "no");
        JSch jsch = new JSch();
        Session jschSession = jsch.getSession(user, host, 2222);
        jschSession.setPassword(password);
        jschSession.connect();
        return (ChannelSftp) jschSession.openChannel("sftp");
    }

}

logs after trying to connect to server from Java" Unable to negotiate with 000.00.0.0 port 54212: no matching host key type found. Their offer: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 [preauth]

justAquestion
  • 19
  • 1
  • 4
  • @MartinPrikryl What do you mean by two different errors? I can't connect via Java to sftp server. – justAquestion Jan 20 '22 at 16:43
  • See [JSchException: Algorithm negotiation fail](https://stackoverflow.com/q/6263630/850848) and for the original problem see [How to resolve Java UnknownHostKey, while using JSch SFTP library?](https://stackoverflow.com/q/32852906/850848) (`StrictHostKeyChecking=no` is a security flaw). Basically, both these have been asked zillion times already. – If neither helps, post [JSch log file](https://stackoverflow.com/q/47411185/850848). + – Martin Prikryl Jan 20 '22 at 16:58

0 Answers0