여기에는 많은 라이브러리가 있습니다. 나는 을 추천하는데, 그 내용은 official OpenSSH website에 언급되어있다. 동일한 사이트에서 Java 용으로 사용할 수있는 다른 라이브러리를 찾을 수도 있습니다.
이
은
ls -r
명령어의 예를 사용하여, SSH 통해 실행 Ganymed SSH-2 :
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
[...]
public static ArrayList<String> lsViaSSH(String hostname, String username, String password, String dir) {
ArrayList<String> ls = new ArrayList<String>();
try
{
Connection conn = new Connection(hostname);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false) {
return null;
}
Session sess = conn.openSession();
sess.execCommand("ls -r " + dir);
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
ls.add(line);
}
sess.close();
conn.close();
}
catch (IOException e)
{
return null;
}
if(StringUtils.isEmpty(ls.get(0)))
return null;
return ls;
}
이 SSH를 통해 명령을 실행하기 위해 필요한 기능 만 아니라, I 그것이있을 수 희망 너에게 좋은 출발점이야.
내가 생각하는 [구글] (https://www.google.co. uk/search? q = java + ssh & ie = utf-8 & oe = utf-8 & aq = t & rls = org.mozilla : ko-ko : 공식 및 클라이언트 = firefox-a & 채널 = fflbh) –