Guest User

Untitled

a guest
Sep 11th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. error in a web service use SSH devlopped with JAVA Axis
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6.  
  7. import ch.ethz.ssh2.Connection;
  8. import ch.ethz.ssh2.Session;
  9. import ch.ethz.ssh2.StreamGobbler;
  10.  
  11. public class ganymed
  12. {
  13. public static string ssh()
  14. { String res="";
  15. String hostname = "10.0.0.20";
  16. String username = "students";
  17. String password = "xxxx";
  18. try
  19. {
  20. /* Create a connection instance */
  21.  
  22. Connection conn = new Connection(hostname);
  23.  
  24. /* Now connect */
  25.  
  26. conn.connect();
  27.  
  28. /* Authenticate.
  29. * If you get an IOException saying something like
  30. * "Authentication method password not supported by the server at this stage."
  31. * then please check the FAQ.
  32. */
  33.  
  34. boolean isAuthenticated = conn.authenticateWithPassword(username, password);
  35.  
  36. if (isAuthenticated == false)
  37. throw new IOException("Authentication failed.");
  38.  
  39. /* Create a session */
  40.  
  41. Session sess = conn.openSession();
  42.  
  43. sess.execCommand("uname -a && date && uptime && who");
  44.  
  45. System.out.println("Here is some information about the remote host:");
  46.  
  47. /*
  48. * This basic example does not handle stderr, which is sometimes dangerous
  49. * (please read the FAQ).
  50. */
  51.  
  52. InputStream stdout = new StreamGobbler(sess.getStdout());
  53.  
  54. BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
  55.  
  56. while (true)
  57. {
  58. String line = br.readLine();
  59. if (line == null)
  60. break;
  61. res +=line;
  62.  
  63. }
  64.  
  65. /* Show exit status, if available (otherwise "null") */
  66.  
  67. System.out.println("ExitCode: " + sess.getExitStatus());
  68.  
  69. /* Close this session */
  70.  
  71. sess.close();
  72.  
  73. /* Close the connection */
  74.  
  75. conn.close();
  76.  
  77. }
  78. catch (IOException e)
  79. {
  80. e.printStackTrace(System.err);
  81. System.exit(2);
  82. }
  83. return res;
  84. }
Add Comment
Please, Sign In to add comment