phanan / remote
此包已废弃且不再维护。未建议替代包。
将 Remote 库带回 Laravel 5。
2.0.1
2015-10-05 11:06 UTC
Requires
- php: >=5.4.0
- phpseclib/phpseclib: 2.0.*
Requires (Dev)
- laravel/framework: ~5.1
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2022-02-14 15:06:04 UTC
README
Remote 是一个简单的包,它将远程连接的能力带回 Laravel 5。此包在幕后使用出色的 phpseclib。
要求
- PHP >= 5.4
- phpseclib 所需的任何内容
安装
首先,在您的 composer.json
中添加 phanan/remote
并运行 composer update
。
"require": {
"laravel/framework": "5.1.*",
"phanan/remote": "2.0.*"
},
下载包后,打开 config/app.php
并添加其服务提供程序类
'providers' => [ /* * Application Service Providers... */ App\Providers\AppServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, PhanAn\Remote\RemoteServiceProvider::class, ],
现在如果您需要示例配置文件——实际上不需要,请参见基于数组的登录使用说明
php artisan vendor:publish
在您的 config
目录下查找 remote.php
文件并将其修改为满足您的需求。
使用
使用 Remote
非常简单:只需初始化一个 PhanAn\Remote\Remote
对象,例如 $connection
。构造函数接受两个参数,均不是必需的
$env
(string|array
):如果是一个字符串,则为在config/remote.php
中找到的远程连接数组的键,如果是一个数组,则为配置数组本身。默认为空字符串,在这种情况下将使用默认连接。$auto_login
(boolean
):连接是否在类构造时尝试登录远程服务器。默认为true
。
这就是魔法发生的地方。实际上是。 Remote
使用魔术方法 __call()
将所有未识别的方法传递给底层的 phpseclib\Net\SFTP
对象。这意味着,您可以直接在 Remote
对象上调用任何 phpseclib\Net\SFTP
方法。
<?php namespace App\Http\Controllers; use Exception; use PhanAn\Remote\Remote; class RemoteController extends Controller { public function getConnect() { $connection = new Remote(); // Of course you can specify a configured environment name, like this // $connection = new Remote('staging'); // // Or even an array, like this // $connection = new Remote([ // 'host' => '::1', // 'port' => 22, // 'username' => 'doge', // 'password' => 'SoIPv6MuchModern', // ]); // All methods below are from \phpseclib\Net\SFTP, not Remote itself! Magic! // Create a file with some dummy content $connection->put('doge', 'Much remote so convenience wow.'); // Execute a command $dir_content = $connection->exec('ls -a'); // Get some standard errors if ($error = $connection->getStdError()) { throw new Exception("Houston, we have a problem: $error"); } } }
有关您可以做什么的详细信息,请参阅 phpseclib 的官方 SFTP 功能列表。
许可证
MIT © Phan An