sbrow/flysystem-ssh-shell

league/flysystem 的 SSH/Shell 适配器

1.0.4 2020-01-24 18:33 UTC

This package is not auto-updated.

Last update: 2024-09-29 12:31:13 UTC


README

SSH shell 的 Flysystem 适配器。

安装

composer require phuxtil/flysystem-ssh-shell 

需求

以下程序需要在本地主机上安装和配置

  • ssh
  • scp

以下程序需要在远程主机上安装

  • find
  • cat
  • stat
  • rmdir
  • mkdir
  • chmod
  • mv
  • rm
  • 兼容 sh 的 shell

配置

使用 League\Flysystem\SshShell\SshShellConfigurator 将选项传递给适配器。

$configurator = (new 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 SshShellConfigurator())
    ->setUser('user')
    ->setHost('host');

注意:这是默认设置。

通过 ssh 私钥

$configurator = (new SshShellConfigurator())
    ->setUser('user')
    ->setHost('host')
    ->setPrivateKey('path/to/id_rsa.private_key');

作为 -i 选项传递给 ssh/scp。

注意:要恢复到默认设置,取消私钥值。

引导

<?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_USERTESTS_SSH_HOST 的环境变量值,或使用以下方式运行测试

TESTS_SSH_USER=... TESTS_SSH_HOST=... vendor/bin/phpunit

注意:TESTS_SSH_PORT 的默认值为 22。