Reputation: 4517
private SSHClient initSSHj(String remoteHost, String username, String password)
throws IOException {
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
client.connect(remoteHost);
client.authPassword(username, password);
return client;
}
protected void uploadFile(
String localFilePath,
String remoteHost,
String username,
String remotePassword,
String remoteFilePath) {
try {
SSHClient sshClient = initSSHj(remoteHost, username, remotePassword);
SFTPClient sftpClient = sshClient.newSFTPClient();
sftpClient.getFileTransfer().setPreserveAttributes(false);
sftpClient.put(localFilePath, remoteFilePath);
sftpClient.close();
sshClient.disconnect();
} catch (IOException ex) {
log.info("Error file to the server :: {}", ex.getMessage());
throw new Exception("Error file to the server");
}
}
The error
{"@timestamp":"2022-02-11T19:38:43.867+05:30","@version":"1","message":"Received SSH_MSG_DISCONNECT (reason=BY_APPLICATION, msg=)","logger_name":"net.schmizz.sshj.transport.TransportImpl","thread_name":"reader","level":"INFO","level_value":20000} {"@timestamp":"2022-02-11T19:38:43.868+05:30","@version":"1","message":"Dying because - ","logger_name":"net.schmizz.sshj.transport.TransportImpl","thread_name":"reader","level":"ERROR","level_value":40000,"stack_trace":"net.schmizz.sshj.transport.TransportException: \n\tat net.schmizz.sshj.transport.TransportImpl.gotDisconnect(TransportImpl.java:565)\n\tat net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:521)\n\tat net.schmizz.sshj.transport.Decoder.decodeMte(Decoder.java:159)\n\tat net.schmizz.sshj.transport.Decoder.decode(Decoder.java:79)\n\tat net.schmizz.sshj.transport.Decoder.received(Decoder.java:231)\n\tat net.schmizz.sshj.transport.Reader.run(Reader.java:60)\n"} {"@timestamp":"2022-02-11T19:38:43.868+05:30","@version":"1","message":"Disconnected - BY_APPLICATION","logger_name":"net.schmizz.sshj.transport.TransportImpl","thread_name":"reader","level":"INFO","level_value":20000}
I have checked username and password, there is no issue. I also have write permission to upload the file in sftp.
From the command line , same creds work for sftp connection.
Upvotes: 0
Views: 4132
Reputation: 718798
The error message means that it (the client) has tried all of the methods of authentication that the server allows (at this time / for this kind of connection) and exhausted them.
Have checked username and password, there is no issue.
It may be that the server does not permit user/password authentication in this context. Maybe it requires public key authentication.
(It is common practice to disallow user / password authentication when connecting to a public IP address. Its a good way to eliminate the risk of hacking by password guessing.)
If you have (for example) fail2ban
set up on the server, it may be that access is temporarily blocked due to too many recent failed attempts to login.
Also have write permission to upload the file in sftp.
That won't be relevant. The session hasn't gotten to the point where it needs to check file's permissions.
Check the server-side logs (e.g. the security log). If there is nothing helpful there, you could try increasing the logging level on the server side (e.g. for sshd
) to get more information about why the authentication is failing.
Upvotes: 1