I am trying to connect to an SFTP server that I created using Docker. When I connect via FileZilla everything is fine.
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]