2017 © Pedro Peláez
 

library ssh-client

Invoke OpenSSH from PHP.

image

ssh-client/ssh-client

Invoke OpenSSH from PHP.

  • Tuesday, October 11, 2016
  • by joostfaassen
  • Repository
  • 3 Watchers
  • 0 Stars
  • 1,065 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 3 % Grown

The README.md

Invoke OpenSSH from PHP., (*1)

$ cat example.php
require_once 'path/to/vendor/autoload.php';

use SSHClient\ClientConfiguration\ClientConfiguration;
use SSHClient\ClientBuilder\ClientBuilder;

# Create a config for the target host

$config = new ClientConfiguration('myhost.example.com', 'boite');
$config->setOptions(array(
    'IdentityFile' => '~/.ssh/id_ed25519',
    'IdentitiesOnly' => 'yes',
));

# Use the config to create a client builder for the target host

$builder = new ClientBuilder($config);

# build a Secure Copy client and copy some files to the target host

$config->setSCPOptions(array('r'));
$scp_client = $builder->buildSecureCopyClient();
$scp_client->copy(
    'path/to/somedir',
    $scp_client->getRemotePath('~/')
);

# build an SSH client and run a command on the target host

$ssh_client = $builder->buildClient();
print($ssh_client->exec(array('cat', '~/somedir/test.txt'))->getOutput());
# end example.php

$ mkdir -p path/to/somedir
$ echo "Let's perform a quirkafleeg." > path/to/somedir/test.txt
$ php example.php
Let's perform a quirkafleeg.
$

OpenSSH's config file can be relied on for configuration of SSH and SCP clients:-, (*2)

$ cat ~/.ssh/config
Host attic attic.example.com
    Hostname attic.example.com
    Port 10022
    IdentitiesOnly yes
    IdentityFile ~/.ssh/id_ed25519
    User willy

$ cat another-example.php
require_once 'path/to/vendor/autoload.php';

use SSHClient\ClientConfiguration\ClientConfiguration;
use SSHClient\ClientBuilder\ClientBuilder;

$config = new ClientConfiguration('attic', 'willy');
$builder = new ClientBuilder($config);

$ssh_client = $builder->buildClient();
print($ssh_client->exec(array('hostname'))->getOutput());
print($ssh_client->exec(array('whoami'))->getOutput());
# end another-example.php

$ php another-example.php
attic.example.com
willy
$

The Versions

11/10 2016

dev-master

9999999-dev

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

11/10 2016

0.1.6

0.1.6.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

15/05 2016

0.1.5

0.1.5.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2016

dev-develop

dev-develop

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2016

0.1.4

0.1.4.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2016

0.1.3

0.1.3.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

02/05 2016

0.1.2

0.1.2.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2016

0.1.0

0.1.0.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/04 2016

0.1.1

0.1.1.0

Invoke OpenSSH from PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires