// Ganymed SSH-2の場合
// (http://www.cleondris.ch/opensource/ssh2/)
//import ch.ethz.ssh2.*
// Orion SSH2の場合
// (http://sourceforge.net/apps/mediawiki/orion-ssh2/index.php?title=Main_Page)
import com.trilead.ssh2.*
host = "192.168.1.100"
username = "user"
password = "password"
// サーバに接続
conn = new Connection(host)
conn.connect()
if( !conn.authenticateWithPassword(username, password) ){
throw new Exception("authentication failed.")
}
// コマンド実行
sess = conn.openSession()
sess.execCommand("""ls -alF""")
// 標準出力
stdout = new BufferedReader(new InputStreamReader(
new StreamGobbler(sess.getStdout()), "UTF-8"))
stdout.eachLine { line ->
println line
}
// 標準エラー出力
stderr = new BufferedReader(new InputStreamReader(
new StreamGobbler(sess.getStderr()), "UTF-8"))
stderr.eachLine { line ->
println line
}
sess.close()
conn.close()
動作環境
groovy 1.7.1, JDK6 Update19, ganymed-ssh2-build250, orion-ssh2-214rc1
○関連項目
0 件のコメント:
コメントを投稿