// Try the authentication
int result = ssh.authenticate(pwd);
// Evaluate the result
if (result == AuthenticationProtocolState.COMPLETE) {
// The connection is authenticated we can now do some real work!
SftpClient sftp = ssh.openSftpClient();
// Make a directory
try {
sftp.mkdir("j2ssh");
}
catch (IOException ex) {
}
// Change directory
sftp.cd("j2ssh");
System.out.println(sftp.pwd());
// Change the mode
sftp.chmod(0777, "j2ssh");
sftp.lcd("c:/");
// Upload a file
sftp.put("system.gif");
// Change the local directory
sftp.lcd("localdir");
// Download a file
sftp.get("somefile.txt", "anotherfile.txt");
// Remove a directory or file
sftp.rm("j2ssh");
// Quit
sftp.quit();
ssh.disconnect();
}
}
catch (Exception e) {
e.printStackTrace();