Search in sources :

Example 1 with SshCommandLineExecutor

use of com.jn.agileway.ssh.client.supports.command.executor.SshCommandLineExecutor in project agileway by fangjinuo.

the class SshCommandLineExecutorTest method testExec.

private void testExec(SshConnectionFactory connectionFactory, AbstractSshConnectionConfig connectionConfig) throws SshException, IOException {
    // connectionConfig.setHost("192.168.234.128");
    connectionConfig.setHost("192.168.1.70");
    connectionConfig.setPort(22);
    connectionConfig.setUser("fangjinuo");
    connectionConfig.setPassword("fjn13570");
    SshConnection connection = connectionFactory.get(connectionConfig);
    SshCommandLineExecutor executor = new SshCommandLineExecutor(connection);
    executor.setWorkingDirectory(new File("~/.java"));
    OutputAsStringExecuteStreamHandler output = new OutputAsStringExecuteStreamHandler();
    executor.setStreamHandler(output);
    executor.execute(CommandLine.parse("ifconfig"));
    showResult(executor);
    System.out.println("====================================");
    executor.execute(CommandLine.parse("ls -al"));
    showResult(executor);
    connection.close();
}
Also used : OutputAsStringExecuteStreamHandler(com.jn.langx.commandline.streamhandler.OutputAsStringExecuteStreamHandler) SshConnection(com.jn.agileway.ssh.client.SshConnection) SshCommandLineExecutor(com.jn.agileway.ssh.client.supports.command.executor.SshCommandLineExecutor) File(java.io.File)

Aggregations

SshConnection (com.jn.agileway.ssh.client.SshConnection)1 SshCommandLineExecutor (com.jn.agileway.ssh.client.supports.command.executor.SshCommandLineExecutor)1 OutputAsStringExecuteStreamHandler (com.jn.langx.commandline.streamhandler.OutputAsStringExecuteStreamHandler)1 File (java.io.File)1