🔑 easier php ssh 🔑
introduction
- SSH2 extension
- PHP 7.2 or newer versions
- PHPUnit >= 8 (for testing purpose)
composer require lotfio/pssh
<?php
// basic usage example
require 'vendor/autoload.php';
$config = [
'host' => 'my-host',
'auth' => new Pssh\Auth\AuthUserPass('lotfio', 'secret')
];
$ssh = new Pssh\Pssh($config);
echo $ssh->exec("date"); // Sat Nov 14 08:10:20 PM CET 2020
- config keys
// additional details
$config = [
'host' => 'server host',
'port' => 'server port || default 22',
'auth' => 'authentication method: AuthUserPass, AuthKeys, AuthHostBasedFile, AuthAgent or AuthNone.',
'timeout' => 'timeout when trying to connect',
'methods' => 'connection method checkout ssh2_connect form more details'
'callbacks' => 'connection callbacks checkout ssh2_connect form more details'
];
- available SSH methods:
$ssh->exec(string $command): string
execute a shell command.$ssh->fingerprint(int $type): string
get connection finger print.$ssh->methodsNegotiated(): array
return an array of negotiated methods.$ssh->addPublicKey(): bool
add a public key.$ssh->removePublicKey(): bool
remove public key.$ssh->listPublicKeys(): array
list public keys.$ssh->tunnel(): resource
open an ssh tunnel.
<?php
require 'vendor/autoload.php';
$config = [
'host' => 'my-host',
'auth' => new Pssh\Auth\AuthUserPass('lotfio', 'secret')
];
$ssh = new Pssh\Pssh($config);
$sftp = new Pssh\Psftp($ssh);
$sftp->copyToServer('local-file', 'remote-file');
- available SSH methods:
$sftp->copyToServer(): bool
copy a file from local to remote server.$sftp->copyFromServer(): bool
copy a file from remote server to local.$sftp->chmod(): bool
change mod file or dir.$sftp->mkdir(): bool
make directory.$sftp->rmdir(): bool
remove directory.$sftp->symlink(): bool
create a symlink.$sftp->symlinkTarget(): string
read symlink target.$sftp->symlinkStat(): array
stating a symlink.$sftp->realpath(): string
get realpath.$sftp->rename(): bool
rename file.$sftp->stat(): array
get file stat.$sftp->unlink(): bool
delete file.
- Thank you for considering to contribute to Package. All the contribution guidelines are mentioned here.
- Here you can find the ChangeLog.
- Share Package and lets get more stars and more contributors.
- If this project helped you reduce time to develop, you can give me a cup of coffee :) : Paypal. 💖
- Package is an open-source software licensed under the MIT license.