SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
try {
ssh.connect("127.0.0.1");
} catch (TransportException e) {
if (e.getDisconnectReason() == DisconnectReason.HOST_KEY_NOT_VERIFIABLE) {
String msg = e.getMessage();
String[] split = msg.split("`");
String vc = split[3];
ssh.close();
ssh = new SSHClient();
ssh.addHostKeyVerifier(vc);
ssh.connect("127.0.0.1");
} else {
throw e;
}
}
try {
ssh.authPassword("test", "test");
final String src = "/home/test";
final SFTPClient sftp = ssh.newSFTPClient();
try {
// sftp.get(src, new FileSystemFile("/tmp"));
} finally {
sftp.close();
}
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("ls -p *.txt | grep -v /");
String[] infs = IOUtils.readFully(cmd.getInputStream()).toString().split("\n");
for (int i = 0; i < infs.length; i++) {
System.out.format("infs[%d] = %s%n", i, infs[i]);
}
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
지난번 sftp hello world 만든다고 매번 키 오류나면 다시 만드는 것 했었는뎅.
뭐 이런 것은 아니겠지얌 ?
댓글 0