Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. public static void main (String args[]) throws IOException {
  2. String user = "username";
  3. String password = "password";
  4. String host = "hostName";
  5. int port=22;
  6. Expect expect=null;
  7.  
  8. try
  9. {
  10. JSch jsch = new JSch();
  11. // jsch.
  12.  
  13. Session session = jsch.getSession(user, host, port);
  14. session.setPassword(password);
  15. session.setConfig("StrictHostKeyChecking", "no");
  16. System.out.println("Establishing Connection...");
  17. session.connect();
  18. Channel channel=session.openChannel("exec");
  19. ((ChannelExec)channel).setCommand("pbrun pbapp wasapp=ksh");
  20. ((ChannelExec)channel).setCommand("ls -l");
  21. channel.connect();
  22.  
  23. System.out.println("connect succcessfully");
  24.  
  25. System.out.println("before command");
  26. System.out.println("after command");
  27. InputStream output= channel.getInputStream();
  28. System.out.println("aafter stream");
  29. int readByte= output.read();
  30. StringBuilder outputBuffer=new StringBuilder();
  31. while(readByte != 0xffffffff)
  32. {
  33.  
  34.  
  35. outputBuffer.append((char)readByte);
  36. readByte = output.read();
  37.  
  38. }
  39.  
  40. System.out.println(outputBuffer.toString());
  41. String s=outputBuffer.toString();
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement