Package net.schmizz.sshj.connection.channel.direct

Examples of net.schmizz.sshj.connection.channel.direct.Session$Subsystem


  }
  private void makeDirectory(JobExecutionContext context) throws GFacHandlerException,GFacException {
    SSHSecurityContext securityContext = (SSHSecurityContext)context.getSecurityContext(SSHSecurityContext.SSH_SECURITY_CONTEXT);
    ApplicationDeploymentDescriptionType app = context.getApplicationContext().getApplicationDeploymentDescription().getType();
    Session session = null;
    try {
      session = securityContext.getSession(context.getApplicationContext().getHostDescription().getType().getHostAddress());

      StringBuilder commandString = new StringBuilder();

      commandString.append("mkdir -p ");
      commandString.append(app.getScratchWorkingDirectory());
      commandString.append(" ; ");
      commandString.append("mkdir -p ");
      commandString.append(app.getStaticWorkingDirectory());
      commandString.append(" ; ");
      commandString.append("mkdir -p ");
      commandString.append(app.getInputDataDirectory());
      commandString.append(" ; ");
      commandString.append("mkdir -p ");
      commandString.append(app.getOutputDataDirectory());

      Command cmd = session.exec(commandString.toString());
      cmd.join(Constants.COMMAND_EXECUTION_TIMEOUT, TimeUnit.SECONDS);
    } catch (ConnectionException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
    } catch (TransportException e) {
      throw new GFacHandlerException(e.getMessage(), e, context);
View Full Code Here


        ssh.connect("localhost");
        try {

            ssh.authPublickey(System.getProperty("user.name"));

            Session sess = ssh.startSession();

            /*
            * It is recommendable to send a fake cookie, and in your ConnectListener when a connection comes in replace
            * it with the real one. But here simply one from `xauth list` is being used.
            */
            sess.reqX11Forwarding("MIT-MAGIC-COOKIE-1", "b0956167c9ad8f34c8a2788878307dc9", 0);

            final Command cmd = sess.exec("/usr/X11/bin/xcalc");

            new StreamCopier(cmd.getInputStream(), System.out).spawn("stdout");
            new StreamCopier(cmd.getErrorStream(), System.err).spawn("stderr");

            // Wait for session & X11 channel to get closed
View Full Code Here

        ssh.connect("localhost");
        try {

            ssh.authPublickey(System.getProperty("user.name"));

            final Session session = ssh.startSession();
            try {

                session.allocateDefaultPTY();

                final Shell shell = session.startShell();

                new StreamCopier(shell.getInputStream(), System.out)
                        .bufSize(shell.getLocalMaxPacketSize())
                        .spawn("stdout");

                new StreamCopier(shell.getErrorStream(), System.err)
                        .bufSize(shell.getLocalMaxPacketSize())
                        .spawn("stderr");

                // Now make System.in act as stdin. To exit, hit Ctrl+D (since that results in an EOF on System.in)
                // This is kinda messy because java only allows console input after you hit return
                // But this is just an example... a GUI app could implement a proper PTY
                new StreamCopier(System.in, shell.getOutputStream())
                        .bufSize(shell.getRemoteMaxPacketSize())
                        .copy();

            } finally {
                session.close();
            }

        } finally {
            ssh.disconnect();
        }
View Full Code Here

        ssh.loadKnownHosts();

        ssh.connect("localhost");
        try {
            ssh.authPublickey(System.getProperty("user.name"));
            final Session session = ssh.startSession();
            try {
                final Command cmd = session.exec("ping -c 1 google.com");
                System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
                cmd.join(5, TimeUnit.SECONDS);
                System.out.println("\n** exit status: " + cmd.getExitStatus());
            } finally {
                session.close();
            }
        } finally {
            ssh.disconnect();
        }
    }
View Full Code Here

        k.init(new File($HOME+"/.haruhi/o2key.pem"));
        ssh.addHostKeyVerifier(new PromiscuousVerifier());

        ssh.connect(ipAddress);
        ssh.authPublickey("ubuntu",k);
        final Session session = ssh.startSession();
        try {
            final Session.Command cmd = session.exec("ls -a");

            System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
            cmd.join(5, TimeUnit.SECONDS);
            System.out.println("\n** exit status: " + cmd.getExitStatus());
        } finally {
            session.close();
            ssh.disconnect();
        }
    }
View Full Code Here

        ssh.addHostKeyVerifier(new PromiscuousVerifier());

        ssh.connect(ipAddress);
        try {
            ssh.authPublickey(clusterUsername, k);
            Session that = ssh.startSession();
            try {
                that.allocateDefaultPTY();
                Session.Shell shell = that.startShell();

                new StreamCopier(shell.getInputStream(), System.out)
                        .bufSize(shell.getLocalMaxPacketSize())
                        .spawn("stdout");

                new StreamCopier(shell.getErrorStream(), System.err)
                        .bufSize(shell.getLocalMaxPacketSize())
                        .spawn("stderr");

                new StreamCopier(System.in, shell.getOutputStream())
                        .bufSize(shell.getRemoteMaxPacketSize())
                        .copy();

            } finally {
                that.close();
            }
        } finally {
            ssh.close();
        }
    }
View Full Code Here

    }
  }

  @Override
  public FileInfo get(URI file) {
    Session session = null;
    try {
      session = getSession(file);
      final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      final InMemoryDestFile destination = new InMemoryDestFile() {
       
View Full Code Here

    }
  }

  @Override
  public void get(URI file, File destination) {
    Session session = null;
    try {
      session = getSession(file);
      ssh.newSCPFileTransfer().download(file.getPath(), destination.getAbsolutePath());
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

    get(file, destination);
  }

  @Override
  public void put(File source, URI destination) {
    Session session = null;
    try {
      session = getSession(destination);
      ssh.newSCPFileTransfer().upload(source.getAbsolutePath(), destination.getPath());
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

    }
  }

  @Override
  public List<URI> list(URI directory) {
    Session session = null;
    try {
      session = getSession(directory);
      final List<URI> uris = new ArrayList<URI>();
      final Command command = session.exec("ls -p1 --group-directories-first /" + directory.getPath());
      final String result = IOUtils.readFully(command.getInputStream()).toString();
     
      for (String line : result.split("[\n\r]+")) {
        if (line.endsWith("/")) {
          final String dir = line.substring(0, line.length() - 2);
View Full Code Here

TOP

Related Classes of net.schmizz.sshj.connection.channel.direct.Session$Subsystem

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.