一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - 如何利用Ganymed SSH-2模擬SSH操作

如何利用Ganymed SSH-2模擬SSH操作

2019-10-11 11:41腳本之家 Java教程

這幾天看SFTP資料時,無意中看到了Ganymed SSH-2,寫了個簡單demo,通過,感覺挺好用的,下面就和大家分享下。需要的朋友可以過來參考參考

官方地址:http://www.cleondris.ch/en/opensource-ssh2.php

簡介:
Ganymed SSH-2 for Java is a library which implements the SSH-2 protocol in pure Java (tested on J2SE 1.4.2 and 5.0). It allows one to connect to SSH servers from within Java programs. It supports SSH sessions (remote command execution and shell access), local and remote port forwarding, local stream forwarding, X11 forwarding, SCP and SFTP. There are no dependencies on any JCE provider, as all crypto functionality is included.

程序:

復制代碼代碼如下:

        @Test
        public void testSsh() {
                String hostname = "192.168.0.1";
                String username = "root";
                String password = "password";
                try {
                        /* Create a connection instance */
                        Connection conn = new Connection(hostname);
                        /* Now connect */
                        conn.connect();
                        System.out.println("connect ok");
                        /*
                         * Authenticate. If you get an IOException saying something like
                         * "Authentication method password not supported by the server at this stage."
                         * then please check the FAQ.
                         */
                        boolean isAuthenticated = conn.authenticateWithPassword(username,password);
                        if (isAuthenticated == false)
                                throw new IOException("Authentication failed.");

                        System.out.println("Authentication ok");
                        /* Create a session */
                        Session sess = conn.openSession();
                        sess.execCommand("uname -a");
                        System.out.println("Here is some information about the remote host:");
                        /*
                         * This basic example does not handle stderr, which is sometimes
                         * dangerous (please read the FAQ).
                         */
                        InputStream stdout = new StreamGobbler(sess.getStdout());
                        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
                        while (true) {
                                String line = br.readLine();
                                if (line == null)
                                        break;
                                System.out.println(line);
                        }
                        /* Show exit status, if available (otherwise "null") */
                        System.out.println("ExitCode: " + sess.getExitStatus());
                        /* Close this session */
                        sess.close();
                        /* Close the connection */
                        conn.close();
                } catch (IOException e) {
                        e.printStackTrace(System.err);
                        System.exit(2);
                }
        }


運行結(jié)果:

復制代碼代碼如下:

connect ok
Authentication ok
Here is some information about the remote host:
Linux localhost.localdomain 2.6.22 #1 SMP Wed Aug 13 11:24:59 CST 2008 i686 i686 i386 GNU/Linux
ExitCode: 0
 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 涩涩屋视频在线观看 | 天天干天天爽天天操 | 久久爽狠狠添AV激情五月 | 黑人巨大精品战中国美女 | 九九九精品视频 | 狠狠色婷婷 | 国产一卡2卡3卡四卡国色天香 | 国产在视频线精品视频 | 久久免费看少妇高潮A片特爽 | 日本tube24xxxxx| 国产永久免费爽视频在线 | 国产精品色拉拉免费看 | 四虎影音先锋 | 日韩一品在线播放视频一品免费 | 午夜国产在线观看 | 日本男女视频 | 操弄哥哥的108种姿势 | 国产日本韩国不卡在线视频 | 亚洲日韩欧美一区二区在线 | 无套内谢大学生A片 | 闺蜜调教我做她的脚奴 | 男人桶女下面60分钟视频 | 日韩欧美一区二区三区免费观看 | 农夫69小说恋老妇小说 | 884aa草莓视频 | 国产日本欧美亚洲精品视 | 青草福利视频 | 水多多凹凸福利视频导航 | 催奶师小说 | 九九久久国产精品免费热6 九九精品视频一区二区三区 | 精品久久香蕉国产线看观看麻豆 | 四虎1515hhh co m | 毛片大全高清免费 | 女性全身裸露无遮挡 | 国产良心大作白丝精厕 | yellow字幕网在线zmzz91 | 91久久偷偷做嫩草影院免费看 | 亚洲第一综合天堂另类专 | 男生同性啪视频在线观看 | 免费一级特黄特色大片 | 亚洲色图色 |