nulvem/remote 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nulvem/remote

最新稳定版本:1.0.4

Composer 安装命令:

composer require nulvem/remote

包简介

SFTP/SSH client library for Laravel

README 文档

README

Total Downloads Latest Version on Packagist License

Remote is an SSH and SFTP connection package for the Laravel Framework. Our elegant solution simplifies even complex tasks with familiar Blade syntax. Experience easy, secure connections without tedious setup.

Installation

Install the composer package:

composer require nulvem/remote

Publish the configuration file:

artisan vendor:publish --provider="Nulvem\Remote\RemoteServiceProvider"

Configuration

Private key file

You can put your private key anywhere in the project, just point the key path in the file /config/remote.php:

[
    'auth' => [
        'key_path' => env('REMOTE_KEY_PATH', storage_path('id_rsa')),
    ],
];

The default path is /storage/id_rsa.

Default username

The default username is root, if you want to change it just add the following variable in the .env file:

REMOTE_USERNAME=dummy

Logging

If you want the log of all executions to be saved, just add the desired channel in the .env file.

REMOTE_LOG_CHANNEL=remote

It is recommended to add the following channel in the file /config/logging.php:

[
    'channels' => [
        'remote' => [
            'driver' => 'daily',
            'path' => storage_path('logs/remote.log'),
            'level' => env('LOG_LEVEL', 'debug'),
            'days' => 14,
        ],
    ],
]

Usage

SSH

Generating scripts

To generate a new remote script use the following command:

php artisan make:remote-script hello-world

A file called hello-world.blade.php will be generated inside the /app/Scripts folder.

If you want to change the default scripts folder, just change the scripts_path property inside the file /config/remote.php.

Executing scripts

use Nulvem\Remote\Facades\Remote;

$remote = Remote::ssh(host: '0.0.0.0');

$remote->run(script: 'hello-world');

If necessary, it is possible to change the default host port:

use Nulvem\Remote\Facades\Remote;

$remote = Remote::ssh(
    host: '0.0.0.0',
    port: 2000
);

$remote->run(script: 'hello-world');

There is no default timeout, scripts may run forever, if necessary, it is possible to change the default host timeout:

use Nulvem\Remote\Facades\Remote;

$remote = Remote::ssh(
    host: '0.0.0.0',
    timeout: 20
);

$remote->run(script: 'hello-world');

If necessary, it is possible to pass any parameters to the SSH script:

echo "Remote script 'install' started"

echo "Hello, my name is {{ $name }}!"
echo "I will list for you the files in the {{ $dir }} directory..."
pwd

echo "Remote script 'install' finished"
$remote = Remote::ssh(host: '0.0.0.0');

$remote->run(
    script: 'hello-world',
    data: [
        'name' => 'John Doe',
        'dir' => '/var/www/html'
    ]
)

Multiple actions on the same connection

use Nulvem\Remote\Facades\Remote;

$remote = Remote::ssh(host: '0.0.0.0');

$remote->run(script: 'install-server');

someLogic();

$remote->run(script: 'configure-server');

SSH output

$remote = Remote::ssh(host: '0.0.0.0');

$execution = $remote->run(script: 'hello-world');

$execution->output();

$execution->success();

$execution->failed();

Warning

Do not remove the last line Remote script 'SCRIPT_NAME' finished on script files, if removed the success() and failed() methods of the output will not work correctly.

SFTP

Downloading files

use Nulvem\Remote\Facades\Remote;

$remote = Remote::sftp(host: '0.0.0.0');

$remote->get(
    from: '/root/sample.json',
    to: storage_path('sample.json')
);

Uploading files

use Nulvem\Remote\Facades\Remote;

$remote = Remote::sftp(host: '0.0.0.0');

$remote->put(from: storage_path('sample.json'));

By default the /root path will be used, if you want to use a custom path:

use Nulvem\Remote\Facades\Remote;

$remote = Remote::sftp(host: '0.0.0.0');

$remote->put(
    from: storage_path('sample.json'),
    to: '/var/www/html'
);

Multiple actions on the same connection

use Nulvem\Remote\Facades\Remote;

$remote = Remote::sftp(host: '0.0.0.0');

$remote->get(
    from: '/root/sample.json',
    to: storage_path('sample.json')
);

someLogicToChangeSampleFile();

$remote->put(from: storage_path('sample.json'));

SFTP output

$remote = Remote::ssh(host: '0.0.0.0');

$execution = $remote->put(from: storage_path('sample.json'));

$execution->success();

$execution->failed();

Security

If you've found a bug regarding security please mail tech@nulvem.com.br instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固