Sample002.java :  » Linux » sshxcute » net » neoremind » sshxcute » sample » Java Open Source

Java Open Source » Linux » sshxcute 
sshxcute » net » neoremind » sshxcute » sample » Sample002.java
package net.neoremind.sshxcute.sample;

import net.neoremind.sshxcute.core.ConnBean;
import net.neoremind.sshxcute.core.IOptionName;
import net.neoremind.sshxcute.core.Result;
import net.neoremind.sshxcute.core.SSHExec;
import net.neoremind.sshxcute.exception.TaskExecFailException;
import net.neoremind.sshxcute.task.CustomTask;
import net.neoremind.sshxcute.task.impl.ExecCommand;
import net.neoremind.sshxcute.task.impl.ExecShellScript;

public class Sample002 {

  public static void main(String[] args) {
    SSHExec ssh = null;
    try {
      ConnBean cb = new ConnBean("rfidic-1.svl.ibm.com", "tsadmin","u7i8o9p0");
      ssh = SSHExec.getInstance(cb);    
      CustomTask abcd = new ExecCommand("abcd");
      ssh.connect();
      Result res = ssh.exec(abcd);
      if (res.isSuccess)
      {
        System.out.println("Return code: " + res.rc);
        System.out.println("sysout: " + res.sysout);
      }
      else
      {
        System.out.println("Return code: " + res.rc);
        System.out.println("error message: " + res.error_msg);
      }
    } catch (TaskExecFailException e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
    } catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
    } finally {
      ssh.disconnect();  
    }
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.