Simple SSH - Code example

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值