ride / lib-system-ssh
SSH system library of the Ride framework
0.1.0
2016-08-30 17:17 UTC
Requires
- ride/lib-log: ^1.0.0
- ride/lib-system: ^1.0.0
This package is auto-updated.
Last update: 2024-12-13 09:01:28 UTC
README
SSH system abstraction library of the PHP Ride framework.
Code Sample
Check this code sample to see the possibilities of this library:
<?php use ride\library\system\System; use ride\library\system\SshSystem; // password authentication $authentication = new PasswordSshAuthentication(); $authentication->setUsername('username'); $authentication->setPasswword('password'); // public key authentication $authentication = new PublicKeySshAuthentication(); $authentication->setUsername('username'); $authentication->setPublicKeyFile('/path/to/public-key'); $authentication->setPrivateKeyFile('/path/to/private-key'); $authentication->setPrivateKeyPassphrase('passphrase'); // optional // create the ssh system $remoteSystem = new SshSystem($authentication, 'my-ssh-host.com', 22); // optional host key verifycation $remoteSystem->setHostKeys(array( 'host:port' => 'fingerprint', )); // optional connect and disconnect $remoteSystem->connect(); $remoteSystem->disconnect(); // check the client $remoteSystem->getClient(); // username // execute a command $output = $remoteSystem->execute('whoami'); $code = null; $output = $remoteSystem->execute('crontab -l', $code); // file system abstraction $remoteFileSystem = $remoteSystem->getFileSystem(); $dir = $remoteFileSystem->getFile('path/to/dir'); $dir->isDirectory(); $dir->isReadable(); $files = $dir->read(); $file = $remoteFileSystem->getFile('path/to/file'); $file->exists(); $file->getModificationTime(); $content = $file->read(); // remote copy $destination = $dir->getChild($file->getName()); $destination = $destination->getCopyFile(); $file->copy($destination); // download a file $localSystem = new System(); $localFileSystem = $localSystem->getFileSystem(); $localFile = $localFileSystem->getFile('path/to/download'); $file->copy($localFile);