moccalotto/ssh
最新稳定版本:v0.6.2
Composer 安装命令:
composer require moccalotto/ssh
包简介
libssh2 wrapper for php
关键字:
README 文档
README
Wrapper for the SSH2 PECL.
#!/usr/bin/env php <?php use Moccalotto\Ssh\Auth; use Moccalotto\Ssh\Session; use Moccalotto\Ssh\Connect; use Moccalotto\Ssh\Terminal; require 'vendor/autoload.php'; $ip = '127.0.0.1'; $username = 'my_username'; $port = 22; $pubkeyfile = '/path/to/my/key/id_rsa'; $privkeyfile = 'path/to/my/key/id_rsa.pub'; $keypass = 'my_password'; /* | Create an SSH session |----------------------- | Connect to specified IP and port, and authorize via SSH key. | You can authorize via password by calling Auth::viaPassword($username, $password) | You can authorize via SSH agent by calling Auth::viaAgent($username) */ $ssh = new Session( Connect::to($ip, $port), Auth::viaKeyFile($username, $pubkeyfile, $privkeyfile, $keypass) ); /* | Open a SFTP channel |--------------------- | Generate a random number, write it to a file on the remote server. | Read the number back from the file. */ $sftp = $ssh->sftp(); $random = mt_rand(); $sftp->putContents('testFile.txt', $random); if ($random == $sftp->getContents('testFile.txt')) { echo 'File testFile.txt was written on remote server, and the contents verified'; echo PHP_EOL; } else { echo 'File testFile.txt was written on remote server, but the contents could not be verified'; echo PHP_EOL; } /* | Create terminal settings |-------------------------- | This step is optional. | You do not need to call $ssh-withTerminal() | If you don't. Default terminal settings will be used. */ $terminal = Terminal::create() ->width(80, 'chars') ->height(25, 'chars'); /* | Execute a single command on the remote server | ---------------------------------------------- | Capture its output and echo it on the local screen. */ echo 'Output of »echo $HOME $PWD«: '; echo $ssh->withTerminal($terminal)->execute('echo $HOME $PWD'); echo PHP_EOL; /* | Send a file via SCP | -------------------- | Simply send this file (demo.php) to the remote server. */ if ($ssh->sendFile(__FILE__, basename(__FILE__))) { printf('File: %s was sent to the remote server'.PHP_EOL, basename(__FILE__)); } /* | Open a shell on the remote server |-------------------------- | Open a shell. | Execute a few commands. | Logout. | Print the output from the shell. | The shell is automatically closed when callback returns. */ echo $ssh->withTerminal($terminal)->shell(function ($shell) { $captured_output = $shell ->writeline('echo The home dir is: $HOME') ->writeline('echo the contents of $PWD is:; ls -lah') ->writeline('logout') ->wait(0.3) // give the shell time to execute the commands. ->readToEnd(); return $captured_output; });
moccalotto/ssh 适用场景与选型建议
moccalotto/ssh 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.16k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ssh」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moccalotto/ssh 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moccalotto/ssh 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moccalotto/ssh 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A flexible FTP, SSL-FTP, and SSH-based SFTP client for PHP. This lib provides helpers that are easy to use to manage the remote files.
Altax is an extensible deployment tool for PHP.
Cisco IOS communications and configuration parsing library
SSH server implementation for ReactPHP
Yoke: SSH Connection Manager/Wallet
ec2dns is a set of command line tools that makes it easy to display public hostnames of EC2 instances and ssh into them via their tag name.
统计信息
- 总下载量: 4.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-13