欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2013年08月30日 09:16:31   作者:  
這幾天看SFTP資料時(shí),無(wú)意中看到了Ganymed SSH-2,寫(xiě)了個(gè)簡(jiǎn)單demo,通過(guò),感覺(jué)挺好用的,下面就和大家分享下。需要的朋友可以過(guò)來(lái)參考參考

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

簡(jiǎn)介:
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.

程序:

復(fù)制代碼 代碼如下:

        @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);
                }
        }

運(yùn)行結(jié)果:
復(fù)制代碼 代碼如下:

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

相關(guān)文章

  • springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn)

    springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn)

    這篇文章主要介紹了springboot單文件下載和多文件壓縮zip下載的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • JFreeChart簡(jiǎn)單實(shí)現(xiàn)光滑曲線繪制

    JFreeChart簡(jiǎn)單實(shí)現(xiàn)光滑曲線繪制

    這篇文章主要為大家詳細(xì)介紹了JFreeChart簡(jiǎn)單實(shí)現(xiàn)光滑曲線的繪制,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-06-06
  • 從入門到精通:Java List遍歷修改的完全指南

    從入門到精通:Java List遍歷修改的完全指南

    在Java中,我們經(jīng)常需要遍歷List集合并對(duì)其中的元素進(jìn)行修改,這可以通過(guò)使用迭代器或for循環(huán)來(lái)實(shí)現(xiàn),需要的朋友可以參考下
    2023-10-10
  • SpringBoot2零基礎(chǔ)到精通之異常處理與web原生組件注入

    SpringBoot2零基礎(chǔ)到精通之異常處理與web原生組件注入

    SpringBoot是Spring全家桶的成員之一,基于約定優(yōu)于配置的思想(即有約定默認(rèn)值,在不配置的情況下會(huì)使用默認(rèn)值,在配置文件下配置的話會(huì)使用配置的值)。SpringBoot是一種整合Spring技術(shù)棧的方式(或者說(shuō)是框架),同時(shí)也是簡(jiǎn)化Spring的一種快速開(kāi)發(fā)的腳手架
    2022-03-03
  • 深入理解Java設(shè)計(jì)模式之迭代器模式

    深入理解Java設(shè)計(jì)模式之迭代器模式

    這篇文章主要介紹了JAVA設(shè)計(jì)模式之迭代器模式的的相關(guān)資料,文中示例代碼非常詳細(xì),供大家參考和學(xué)習(xí),感興趣的朋友可以了解
    2021-11-11
  • java開(kāi)發(fā)分布式服務(wù)框架Dubbo調(diào)用過(guò)程

    java開(kāi)發(fā)分布式服務(wù)框架Dubbo調(diào)用過(guò)程

    這篇文章主要為大家介紹了java開(kāi)發(fā)分布式服務(wù)框架Dubbo調(diào)用過(guò)程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2021-11-11
  • 詳解Java面向?qū)ο笾械睦^承

    詳解Java面向?qū)ο笾械睦^承

    這篇文章主要介紹了詳解Java面向?qū)ο笾械睦^承,繼承提高代碼的復(fù)用性:通過(guò)繼承,子類可以直接使用父類的屬性和方法,不需要重復(fù)定義,需要的朋友可以參考下
    2023-05-05
  • Java小程序賽馬游戲?qū)崿F(xiàn)過(guò)程詳解

    Java小程序賽馬游戲?qū)崿F(xiàn)過(guò)程詳解

    這篇文章主要介紹了Java小程序賽馬游戲?qū)崿F(xiàn)過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-03-03
  • 聊聊在Servlet中怎么上傳文件

    聊聊在Servlet中怎么上傳文件

    很多朋友不清楚在Servlet中怎么上傳文件,談到這個(gè)問(wèn)題,首先需要我們掌握開(kāi)發(fā)servlet的步驟,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2021-05-05
  • Java中間消息件ActiveMQ使用實(shí)例

    Java中間消息件ActiveMQ使用實(shí)例

    這篇文章主要介紹了Java中間消息件ActiveMQ使用實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11

最新評(píng)論