Package com.sshtools.j2ssh.session

Examples of com.sshtools.j2ssh.session.SessionChannelClient


      // Try the authentication
      int result = ssh.authenticate(pwd);
      // Evaluate the result
      if (result == AuthenticationProtocolState.COMPLETE) {
        // The connection is authenticated we can now do some real work!
        SessionChannelClient session = ssh.openSessionChannel();
        if(!session.requestPseudoTerminal("vt100", 80, 24, 0, 0, ""))
          System.out.println("Failed to allocate a pseudo terminal");
        if (session.startShell()) {
          IOStreamConnector input =
              new IOStreamConnector();
          IOStreamConnector output =
              new IOStreamConnector();
          IOStreamConnector error =
              new IOStreamConnector();
          output.setCloseOutput(false);
          input.setCloseInput(false);
          error.setCloseOutput(false);
          input.connect(System.in, session.getOutputStream());
          output.connect(session.getInputStream(), System.out);
          error.connect(session.getStderrInputStream(), System.out);
          session.getState().waitForState(ChannelState.CHANNEL_CLOSED);
        }else
          System.out.println("Failed to start the users shell");
        ssh.disconnect();
      }
    }
View Full Code Here


  public String execCmd(String cmd){
    String theOutput = "";
    try
    {
      // The connection is authenticated we can now do some real work!
      SessionChannelClient session = ssh.openSessionChannel();

      if ( session.executeCommand(cmd)){
        IOStreamConnector output = new IOStreamConnector();
        java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
        output.connect(session.getInputStream(), bos );
        session.getState().waitForState(ChannelState.CHANNEL_CLOSED);
        theOutput = bos.toString();
        //System.out.println();
        resultCommand=true;
      }
      else
View Full Code Here

    private boolean sendRestart(String command) {

  try {
    // Open a session channel
    System.out.println("Con7");   
     SessionChannelClient session = ssh.openSessionChannel();
     System.out.println("Con8");   
     // Request a pseudo terminal, if you do not you may not see the prompt
     if(session.requestPseudoTerminal("ansi", 80, 24, 0, 0, "")) {
       System.out.println("Con8a");     
       // Start the users shell
       if(session.startShell()) {
         System.out.println("Con8b");     
         // Do something with the session output
         //session.getOutputStream().write(command+"\n");
         boolean r = session.executeCommand(command);
         System.out.println("Con8c");     
         return r;
        
       }
       System.out.println("Con8d");     
View Full Code Here

                        + "authentication is required");
            } else if(result==AuthenticationProtocolState.COMPLETE) {
                log.info("ssh client authentication is complete...");
            }
            GFacUtils.saveJobStatus(jobExecutionContext, details, JobState.SUBMITTED);
            SessionChannelClient session = sshClient.openSessionChannel();
            log.info("ssh session successfully opened...");
            session.requestPseudoTerminal("vt100", 80, 25, 0, 0, "");
            session.startShell();
            GFacUtils.saveJobStatus(jobExecutionContext, details, JobState.ACTIVE);
             
            session.getOutputStream().write(shellCmd.getBytes());

            InputStream in = session.getInputStream();
            byte buffer[] = new byte[255];
            int read;
            String executionResult = "";
            while((read = in.read(buffer)) > 0) {
                String out = new String(buffer, 0, read);
View Full Code Here

        ChannelEventListener eventListener) throws IOException {
        if (authenticationState != AuthenticationProtocolState.COMPLETE) {
            throw new SshException("Authentication has not been completed!");
        }

        SessionChannelClient session = new SessionChannelClient();
        session.addEventListener(activeChannelListener);

        if (!connection.openChannel(session, eventListener)) {
            throw new SshException("The server refused to open a session");
        }
View Full Code Here

     * @throws IOException
     * @throws SshException
     */
    public SftpSubsystemClient openSftpChannel(
        ChannelEventListener eventListener) throws IOException {
        SessionChannelClient session = openSessionChannel(eventListener);
        SftpSubsystemClient sftp = new SftpSubsystemClient();

        if (!openChannel(sftp)) {
            throw new SshException("The SFTP subsystem failed to start");
        }
View Full Code Here

                        + "authentication is required");
            } else if(result==AuthenticationProtocolState.COMPLETE) {
                log.info("ssh client authentication is complete...");
            }
            GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.SUBMITTED);
            SessionChannelClient session = sshClient.openSessionChannel();
            log.info("ssh session successfully opened...");
            session.requestPseudoTerminal("vt100", 80, 25, 0, 0, "");
            session.startShell();
           
            GFacUtils.updateApplicationJobStatus(jobExecutionContext, jobId, ApplicationJobStatus.EXECUTING);
            session.getOutputStream().write(shellCmd.getBytes());

            InputStream in = session.getInputStream();
            byte buffer[] = new byte[255];
            int read;
            String executionResult = "";
            while((read = in.read(buffer)) > 0) {
                String out = new String(buffer, 0, read);
View Full Code Here

TOP

Related Classes of com.sshtools.j2ssh.session.SessionChannelClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.