lotfio/pssh

更简单的 PHP SSH

dev-master 2021-01-23 13:37 UTC

This package is auto-updated.

Last update: 2024-09-23 21:38:19 UTC


README

skeleton Preview

License PHP version Version Coverage Build Status StyleCi

🔑 更简单的 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

📃 变更日志

🍺 支持开发

  • 分享 并让我们获得更多星标和贡献者。
  • 如果这个项目帮助您减少了开发时间,您可以给我一杯咖啡 :) : Paypal. 💖

📋 许可证