Below is a example section of my java 1.8 program. It appears to be failing when trying to authenticate. It goes through a number of authentication methods and then declares its run out. I would like to see debug information from within the sshj library to help me determine what's failing :- username, key exchange or something else. I am familiar with log4j and I can put logging statements within my code, but I can't find an example (simple to follow) which shows me how to hook up log4j to sfl4j and then tell sshj to use the logger.
'''
SSHClient sshClient = new SSHClient();
try
{
String username = "testuser";
File privateKey = new File("/mykeys/keyname");
KeyProvider keys;
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
keys = sshClient.loadKeys(privateKey.getPath());
sshClient.connect("1.2.3.4", 22);
sshClient.authPublickey(username, keys);
SFTPClient sftpClient = sshClient.newSFTPClient();
sftpClient.put("./send/file1.xml", "file1.xml");
sshClient.close();
}
catch (UserAuthException e)
{
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
catch (TransportException e)
{
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
catch (IOException e)
{
// TODO Auto-generated catch block
System.out.println(e.getMessage());
}
'''
Adding
to pom.xml
and creating a log4j.proerties files did the trick for me: