SSH客户端开发开源组件Ganymed SSH-2 for Java初体验
2017-05-26 14:25
253 查看
1、Ganymed SSH-2 for Java
Ganymed SSH-2 for Java是一个纯Java实现的SHH2库。
看官方介绍:
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.
2、开源组件下载地址:http://www.ganymed.ethz.ch/ssh2/
解压后如下:
ganymed-ssh2-build210.jar引入工程包,javadoc是学习文档,examples是开发案例。
3、开发案例Basic代码参考:
Ganymed SSH-2 for Java是一个纯Java实现的SHH2库。
看官方介绍:
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.
2、开源组件下载地址:http://www.ganymed.ethz.ch/ssh2/
解压后如下:
ganymed-ssh2-build210.jar引入工程包,javadoc是学习文档,examples是开发案例。
3、开发案例Basic代码参考:
package com.ssh; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.Session; import ch.ethz.ssh2.StreamGobbler; public class Basic { public static void main(String[] args) { String hostname = "172.0.0.1"; String username = "hdfs"; String password = "hdfs"; try { /* Create a connection instance */ Connection conn = new Connection(hostname); /* Now connect */ conn.connect(); /* 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."); /* Create a session */ Session sess = conn.openSession(); sess.execCommand("uname -a && date && uptime && who"); 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); } } }
相关文章推荐
- 开发 .NET 下的 FTP 客户端组件
- 基于apache组织的commonNet开源组件实现ftp客户端的上传功能
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- 第8章 C# .NET 开源可进行二次开发的即时通讯组件提供全部源码下载
- 第8章 C# .NET 开源可进行二次开发的即时通讯组件提供全部源码下载
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- [VB开源]KillIt :ASP/COM+组件开发辅助软件
- 开发 .NET 下的 FTP 客户端组件
- RooyeeMessenger由Delphi开发的XMPP即时通讯客户端(免费开源)
- 第8章 C# .NET 开源可进行二次开发的即时通讯组件提供全部源码下载
- 开发 .NET 下的 FTP 客户端组件
- 用VC写的一个IM客户端,基于一个开源的gloox库开发
- 【网络存储】服务器 NSTP 协议客户端组件开发指南
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探
- flashbox小组件开发~~开源~~
- Asp.Net Ajax 学习笔记24 利用Microsoft AJAX Library开发客户端组件(中)
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- ASP.NET 3.5控件和组件开发技术之客户端回发/回调揭密