Pessoal,
Estou usando a Ganymede SSH para conexão ssh, quero usar ela para acesso a equipamentos da onde trabalho, poreḿ tenho um problema quando eu conecto em uma maquina linux funciona normalmente o código abaixo, agora quando eu faço a conexão para o equipamento é lançado a exceção
public class Main {
public void connect(){
}
public static void main(String[] arg) throws InterruptedException {
String hostname = "10.227.1.1";
String username = "manager";
String password = "";
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("ls");
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);
}
}
}
run:
java.io.IOException: The execute request failed.
at ch.ethz.ssh2.channel.ChannelManager.requestExecCommand(ChannelManager.java:703)
at ch.ethz.ssh2.Session.execCommand(Session.java:249)
at javaapplication10.Main.main(Main.java:62)
Caused by: java.io.IOException: This SSH2 channel is not open (Close requested by remote)
at ch.ethz.ssh2.channel.ChannelManager.waitForChannelSuccessOrFailure(ChannelManager.java:174)
at ch.ethz.ssh2.channel.ChannelManager.requestExecCommand(ChannelManager.java:699)
... 2 more
Java Result: 2