-
大小: 585KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-05-14
- 语言: Java
- 标签: ganymed-ssh2
资源简介
Java ganymed-ssh2 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 = “127.0.0.1“;
String username = “joe“;
String password = “joespass“;
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);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\
文件 2001 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\ChannelCondition.java
文件 44556 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\Connection.java
文件 1374 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\ConnectionInfo.java
文件 1229 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\ConnectionMonitor.java
文件 3704 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\DHGexParameters.java
文件 3185 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\HTTPProxyData.java
文件 783 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\HTTPProxyException.java
文件 2483 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\InteractiveCallback.java
文件 22037 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\KnownHosts.java
文件 1223 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\LocalPortForwarder.java
文件 2333 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\LocalStreamForwarder.java
文件 322 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\ProxyData.java
文件 18775 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SCPClient.java
文件 2143 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SFTPException.java
文件 39052 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SFTPv3Client.java
文件 1226 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SFTPv3DirectoryEntry.java
文件 3938 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SFTPv3FileAttributes.java
文件 955 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\SFTPv3FileHandle.java
文件 1244 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\ServerHostKeyVerifier.java
文件 14752 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\Session.java
文件 5408 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\StreamGobbler.java
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\auth\
文件 10753 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\auth\AuthenticationManager.java
目录 0 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\channel\
文件 6201 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\channel\Channel.java
文件 1642 2006-10-10 10:35 ganymed-ssh2-build210\src\ch\ethz\ssh2\channel\ChannelInputStream.java
............此处省略190个文件信息
- 上一篇:七牛云存储上传、等
- 下一篇:jackson-all-1.9.2.jar包
评论
共有 条评论