lotfio / pssh
更简单的 PHP SSH
dev-master
2021-01-23 13:37 UTC
Requires
- php: >=7.4
- ext-ssh2: *
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-23 21:38:19 UTC
README
🔑 更简单的 PHP SSH 🔑
🔥 简介
简介
📌 要求
- SSH2 扩展
- PHP 7.2 或更高版本
- PHPUnit >= 8(用于测试目的)
🚀 安装 & 使用
composer require lotfio/pssh
✏️ SSH
<?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
⚙️ 配置
- 配置密钥
// 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' ];
- 可用的 SSH 方法
$ssh->exec(string $command): string执行一个 shell 命令。$ssh->fingerprint(int $type): string获取连接指纹。$ssh->methodsNegotiated(): array返回协商方法数组。$ssh->addPublicKey(): bool添加公钥。$ssh->removePublicKey(): bool删除公钥。$ssh->listPublicKeys(): array列出公钥。$ssh->tunnel(): resource打开 SSH 隧道。
✏️ SFTP
<?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');
- 可用的 SSH 方法
$sftp->copyToServer(): bool从本地复制文件到远程服务器。$sftp->copyFromServer(): bool从远程服务器复制文件到本地。$sftp->chmod(): bool改变文件或目录的权限。$sftp->mkdir(): bool创建目录。$sftp->rmdir(): bool删除目录。$sftp->symlink(): bool创建符号链接。$sftp->symlinkTarget(): string读取符号链接的目标。$sftp->symlinkStat(): array获取符号链接的属性。$sftp->realpath(): string获取真实路径。$sftp->rename(): bool重命名文件。$sftp->stat(): array获取文件属性。$sftp->unlink(): bool删除文件。
💻 贡献
- 感谢您考虑为 包 做贡献。所有贡献指南都在这里:CONTRIBUTING.md。
📃 变更日志
- 您可以在CHANGELOG.md中找到变更日志。
🍺 支持开发
- 分享 包 并让我们获得更多星标和贡献者。
- 如果这个项目帮助您减少了开发时间,您可以给我一杯咖啡 :) : Paypal. 💖
📋 许可证
- 包 是一个开源软件,根据MIT 许可证授权。
