1 16 package examples; 17 18 import java.io.IOException ; 19 import org.apache.commons.net.bsd.RCommandClient; 20 21 38 39 public final class rshell 41 { 42 43 public static final void main(String [] args) 44 { 45 String server, localuser, remoteuser, command; 46 RCommandClient client; 47 48 if (args.length != 4) 49 { 50 System.err.println( 51 "Usage: rshell <hostname> <localuser> <remoteuser> <command>"); 52 System.exit(1); 53 return ; } 55 56 client = new RCommandClient(); 57 58 server = args[0]; 59 localuser = args[1]; 60 remoteuser = args[2]; 61 command = args[3]; 62 63 try 64 { 65 client.connect(server); 66 } 67 catch (IOException e) 68 { 69 System.err.println("Could not connect to server."); 70 e.printStackTrace(); 71 System.exit(1); 72 } 73 74 try 75 { 76 client.rcommand(localuser, remoteuser, command); 77 } 78 catch (IOException e) 79 { 80 try 81 { 82 client.disconnect(); 83 } 84 catch (IOException f) 85 {} 86 e.printStackTrace(); 87 System.err.println("Could not execute command."); 88 System.exit(1); 89 } 90 91 92 IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), 93 System.in, System.out); 94 95 try 96 { 97 client.disconnect(); 98 } 99 catch (IOException e) 100 { 101 e.printStackTrace(); 102 System.exit(1); 103 } 104 105 System.exit(0); 106 } 107 108 } 109 110 | Popular Tags |