phuxtil / flysystem-ssh-shell
league/flysystem 的 SSH/Shell 适配器
3.0.3
2021-08-09 17:00 UTC
Requires
- php: ^8
- league/flysystem: ^1
- phuxtil/find: ^3
- phuxtil/stat: ^3
- symfony/process: ^4|^5
Requires (Dev)
- ext-posix: *
- phpunit/phpunit: ^9
- popo/generator: ^5
- symfony/var-dumper: ^5
This package is auto-updated.
Last update: 2024-09-05 09:15:21 UTC
README
Flysystem 的 SSH shell 适配器。
安装
composer require phuxtil/flysystem-ssh-shell
注意: 使用 v1.x 以兼容 PHP v7.0.x 注意: 使用 v2.x 以兼容 PHP v7.2+
要求
以下程序已安装在本地主机并配置
- ssh
- scp
以下程序已安装在远程主机上
- find
- cat
- stat
- rmdir
- mkdir
- chmod
- mv
- rm
- 兼容的 shell
配置
使用 \Phuxtil\Flysystem\SshShell\SshShellConfigurator
将选项传递给适配器。
$configurator = (new \Phuxtil\Flysystem\SshShell\SshShellConfigurator()) ->setRoot('/remote_server/path') ->setUser('remote_user') ->setHost('remote-ssh-host') ->setPrivateKey('path/to/id_rsa.private_key') ->setPort(22);
认证
支持两种认证方法
通过 ssh 配置文件
user@host
的值配置在 ssh 配置文件中。
$configurator = (new \Phuxtil\Flysystem\SshShell\SshShellConfigurator()) ->setUser('user') ->setHost('host');
注意:这是默认设置。
通过 ssh 私钥
$configurator = (new \Phuxtil\Flysystem\SshShell\SshShellConfigurator()) ->setUser('user') ->setHost('host') ->setPrivateKey('path/to/id_rsa.private_key');
作为 ssh/scp 的 -i
选项传递。
注意:要恢复默认设置,取消私钥的值。
引导
<?php use League\Flysystem\Filesystem; use Phuxtil\Flysystem\SshShell\SshShellConfigurator; use Phuxtil\Flysystem\SshShell\SshShellFactory; \error_reporting(\E_ALL); include __DIR__ . '/vendor/autoload.php'; $configurator = (new SshShellConfigurator()) ->setRoot('/tmp/remote_fs') ->setUser('user') ->setHost('host'); $adapter = (new SshShellFactory())->createAdapter($configurator); $filesystem = new Filesystem($adapter);
测试驱动开发(TDD)
远程主机的默认根目录是 /tmp/remote_fs
。
可用参数
TESTS_SSH_USER
TESTS_SSH_HOST
TEST_SSH_PORT
(可选,默认 22)
使用以下命令运行测试
TESTS_SSH_USER=... TESTS_SSH_HOST=... vendor/bin/phpunit --group acceptance