Example usage for org.apache.commons.net.ssh.connection Session allocateDefaultPTY

List of usage examples for org.apache.commons.net.ssh.connection Session allocateDefaultPTY

Introduction

In this page you can find the example usage for org.apache.commons.net.ssh.connection Session allocateDefaultPTY.

Prototype

void allocateDefaultPTY() throws ConnectionException, TransportException;

Source Link

Document

Allocates a default PTY.

Usage

From source file:examples.ssh.RudimentaryPTY.java

public static void main(String... args) throws IOException {
    SSHClient ssh = new SSHClient();

    ssh.loadKnownHosts();/*from  w  w w .  j  a va 2s.  c  o  m*/

    ssh.connect("localhost");

    Shell shell = null;

    try {

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

        Session session = ssh.startSession();
        session.allocateDefaultPTY();

        shell = session.startShell();

        new Pipe("stdout", shell.getInputStream(), System.out) //
                .bufSize(shell.getLocalMaxPacketSize()) //
                .start();

        new Pipe("stderr", shell.getErrorStream(), System.err) //
                .bufSize(shell.getLocalMaxPacketSize()) //
                .start();

        // 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

        Pipe.pipe(System.in, shell.getOutputStream(), shell.getRemoteMaxPacketSize(), false);

    } finally {

        if (shell != null)
            shell.close();

        ssh.disconnect();
    }
}