激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

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

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

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

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

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

這幾天看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
 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 人成免费a级毛片 | 男女隐私免费视频 | 黄色片在线观看网站 | 久久久久夜色精品国产老牛91 | av在线播放免费观看 | h色在线观看 | 欧美18—19sex性hd按摩 | qyl在线视频精品免费观看 | 爽爽淫人综合网网站 | 毛片大全免费看 | 久久精品99北条麻妃 | 国产91av视频 | 黄色片免费看网站 | 国产成人高清在线观看 | 草久影院 | 竹内纱里奈和大战黑人 | 日韩区在线 | 国产精品视频一区二区噜噜 | 欧美中文日韩 | 色综合久久久久综合99 | 精品欧美一区二区精品久久 | 久在线草| 午夜精品老牛av一区二区三区 | 欧美日韩一区,二区,三区,久久精品 | 国产精品久久久久久久av | www.xxx视频| 欧美一级美片在线观看免费 | 日韩在线播放一区二区 | 91 免费视频 | 成人久久 | xxxⅹ96日本护士hd | 海外中文字幕在线观看 | 黄色网址在线免费 | 亚洲一区在线视频观看 | 国产一区二区三区四区在线 | 成人综合在线观看 | 成年免费观看视频 | cosplay裸体福利写真 | 妇女毛片| 国产一区二区三区撒尿在线 | 日日狠狠久久偷偷四色综合免费 |