J2SSH

import java.io.BufferedReader;
 2 import java.io.IOException;
 3 import java.io.InputStreamReader;
 4 import java.io.OutputStream;
 5 
 6 import com.sshtools.j2ssh.SshClient;
 7 import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
 8 import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
 9 import com.sshtools.j2ssh.session.SessionChannelClient;
10 
11 public class Main {
12 
13     public static void main(String[] args) {
14         SshClient ssh = new SshClient();
15         PasswordAuthenticationClient authentication = new PasswordAuthenticationClient();
16         authentication.setUsername("root");
17         authentication.setPassword("123");
18         try {
19             ssh.connect("192.168.94.254", 22, new HostsKeyVerification());
20             if (ssh.authenticate(authentication) == AuthenticationProtocolState.COMPLETE) {
21                 SessionChannelClient session = ssh.openSessionChannel();
22                 // session.setEnvironmentVariable("TERM", "linux");
23                 // if (client.requestPseudoTerminal("vt100", 120, 400, 0, 0,
24                 // "")) {
25                 if (session.startShell()) {
26                     OutputStream writer = session.getOutputStream();
27                     writer.write("echo $?\n".getBytes());
28                     writer.flush();
29                     writer.write("exit\n".getBytes());
30                     writer.flush();
31                     BufferedReader in = new BufferedReader(
32                             new InputStreamReader(session.getInputStream()));
33                     BufferedReader err = new BufferedReader(
34                             new InputStreamReader(session
35                                     .getStderrInputStream()));
36                     String line;
37                     while ((line = in.readLine()) != null) {
38                         System.out.println(line);
39                     }
40                     System.out.println("------------------------");
41                     while ((line = err.readLine()) != null) {
42                         System.out.println(line);
43                     }
44                     if (session != null) {
45                         session.close();
46                     }
47                 }
48                 // }
49             }
50         } catch (IOException e) {
51             e.printStackTrace();
52         } finally {
53         }
54 
55     }
56 
57 }

转载于:https://www.cnblogs.com/ylqmf/archive/2012/06/28/2567904.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
文件内容: ``` <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sshtools</groupId> <artifactId>j2ssh-core</artifactId> <version>0.2.2</version> <packaging>jar</packaging> <name>j2ssh-core</name> <description>J2SSH is a pure Java implementation of the SSH2 protocol suite</description> <url>http://www.sshtools.com/?go=products.ssh</url> <licenses> <license> <name>GNU Lesser General Public License, Version 2.1</name> <url>http://www.gnu.org/licenses/lgpl-2.1.txt</url> <distribution>repo</distribution> </license> </licenses> <developers> <developer> <id>lee</id> <name>Lee David Painter</name> <email>lee@sshtools.com</email> <url>http://www.sshtools.com/</url> <organization>SSHTOOLS Limited</organization> <organizationUrl>http://www.sshtools.com/</organizationUrl> <roles> <role>Developer</role> </roles> </developer> </developers> <scm> <connection>scm:svn:http://svn.sshtools.com/j2ssh/trunk</connection> <developerConnection>scm:svn:https://svn.sshtools.com/j2ssh/trunk</developerConnection> <url>http://svn.sshtools.com/j2ssh/trunk</url> </scm> <dependencies> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcpg-jdk14</artifactId> <version>1.45</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.bouncycastle</groupId> <artifactId>bcprov-jdk14</artifactId> <version>1.45</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.jcraft</groupId> <artifactId>jzlib</artifactId> <version>1.1.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.sshtools</groupId> <artifactId>jlzma</artifactId> <version>0.0.1</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.8.1</version> <executions> <execution> <id>attach-javadocs</id> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> ``` 该pom文件描述了j2ssh-core-0.2.2.jar的元数据,包括以下内容: - groupId、artifactId、version、packaging:标识了该jar包的基本信息; - name、description、url:提供了对该jar包的描述和相关信息; - licenses:声明了该jar包采用的开源许可证; - developers:列出了参与该jar包开发的人员信息; - scm:指定了该jar包的源码管理信息; - dependencies:列出了该jar包所依赖的其他jar包; - build:提供了构建该jar包的插件配置信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值