在這個網址下載一個調用ssh和scp命令的jar包
然後
package hh;
import java
import ch
public class Basic
{
public static void main(String[] args)
{
String hostname =
String username =
String password =
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
nnect();
/* Authenticate */
boolean isAuthenticated = conn
if (isAuthenticated == false)
throw new IOException(
/* Create a session */
Session sess = conn
//sess
sess
System
InputStream stdout = new StreamGobbler(sess
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br
if (line == null)
break;
System
}
/* Show exit status
System
/* Close this session */
sess
/* Close the connection */
conn
}
catch (IOException e)
{
e
}
}
}
在控制台我們將看到輸出結果
很簡單
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26951.html