Guest User

Untitled

a guest
Oct 8th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. public static void main(String args[])
  2. {
  3. String host="xxxxx.yyyy.com";
  4. String user="user";
  5. String password="password";
  6. String command1="dzdo su - lucy";
  7. try{
  8. java.util.Properties config = new java.util.Properties();
  9. config.put("StrictHostKeyChecking", "no");
  10. JSch jsch = new JSch();
  11. Session session=jsch.getSession(user, host, 22);
  12. session.setPassword(password);
  13. session.setConfig(config);
  14. session.connect();
  15. System.out.println("Connected");
  16.  
  17. Channel channel=session.openChannel("shell");
  18. OutputStream ops = channel.getOutputStream();
  19. PrintStream ps = new PrintStream(ops, true);
  20.  
  21. channel.connect();
  22. ps.println(command1);
  23. ps.println("ls -ltr");
  24. InputStream in=channel.getInputStream();
  25. byte[] tmp=new byte[1024];
  26. while(true){
  27. while(in.available()>0){
  28. int i=in.read(tmp, 0, 1024);
  29. if(i<0)break;
  30. System.out.print(new String(tmp, 0, i));
  31. }
  32. if(channel.isClosed()){
  33. System.out.println("exit-status: "+channel.getExitStatus());
  34. break;
  35. }
  36. try{Thread.sleep(1000);}catch(Exception ee){}
  37. }
  38. channel.disconnect();
  39. session.disconnect();
  40. System.out.println("DONE");
  41. }catch(Exception e){
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46.  
  47. drwxrws---. 2 gleaiid gleai 4096 Jan 21 2016 [0m[01;34mold[0m
  48. -rwxrws---. 1 jhon gleai 100 Jul 20 2017 [30;43mNVISAP_814_Test.txt[0m
  49. -rwxrws---. 1 jhon gleai 134 Jul 20 2017 [30;43mUS_NISC14_4164556_Test.txt[0m
  50. -rwxrws---. 1 jhon gleai 0 Jul 20 2017 [30;43mNVISAP_R00814_Test.trg[0m
Add Comment
Please, Sign In to add comment