package com.xxx.mobile.util;
import java.io.*;
import ch.ethz.ssh2.*;
public class simpleSSH {
public static void main(String[] args) throws IOException {
Connection conn = new Connection("xx.xxx.xx.xxx");
conn.connect();
File pemKeyFile = new File("mailcontrol");
boolean isAuth = conn.authenticateWithPublicKey("mailcontrol", pemKeyFile, "xxx");
if (isAuth == false) {
throw new IOException("Authenticationfailed.");
}
Session sess = conn.openSession();
//sess.execCommand("netstat -nl | egrep':80' | wc -l");
sess.execCommand("ls -nl");
InputStream inp = sess.getStdout();
InputStreamReader reader = newInputStreamReader(inp);
BufferedReader br = new BufferedReader(reader);
String line=null;
while (true)
{
line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
sess.close();
conn.close();
}
}
total 21892
-rw-rw-r-- 1 500 500 2276Aug 29 09:58 1
-rw-r--r-- 1 500 500 9417247 Nov 23 10:20app.all.log
-rw-r--r-- 1 500 500 5575712 Nov 23 10:20app.cap
-rw-r--r-- 1 500 500 6973712 Nov 23 10:21app.log.lync
-rw-rw-r-- 1 500 500 20125 Oct 3113:50 ashleyb
-rw------- 1 500 500 674 Aug 1 07:16 authorized_keys2
-rw------- 1 500 500 589 Aug 1 07:15 authorized_keys2.~orig
drwxr-xr-x 7 500 0 4096 Nov 6 14:36 bbc30
drwxrwx--- 2 500 500 4096Aug 21 2011 bin
-rwxr-xr-x 1 500 500 1867Sep 14 08:00 checkcluster
drwxrwx--- 2 500 500 4096Aug 21 2011 fwupdate
-rw-rw-r-- 1 500500 37 Jun 27 00:10 mon.sh
-rw------- 1 500 500 172922 Nov 1613:03 nohup.out
-rw-rw-r-- 1 500500 3 Sep 21 09:26 result
-rw-rw-r-- 1 500 500 753 Sep 5 03:41 server.csr
-rw-rw-r-- 1 500 500 963 Sep 5 03:39 server.key
-rw-rw-r-- 1 500500 70 Jun 27 00:15 settime.sh
-rw-rw-r-- 1 500 500 1036Sep 20 09:43 t.txt
drwxr-xr-x 2 0 0 4096 Aug 21 2011 test
-rw-rw-r-- 1 500 500 110160 Oct 3111:00 toproduction.sh
drwxr-xr-x 2 0 0 4096 Aug 21 2011 utils-product
-r-xr-xr-x 1 500 500 2851Feb 28 2012 vpn_templete.plist
-rwxr-xr-x 1 500 500 20128 Nov 16 05:37 zapcluster2