1.0.5 • Published 4 years ago

egg-ssh v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

egg-ssh

NPM version npm download

一款基于node-ssh,它基于ssh2的egg链接ssh的插件。 主要api参考node-ssh

拓展API

class EggSSH extends NodeSSH{
    
    constructor(config:Config)

    // 自动连接
    autoConnect(config?:Config):Promise<EggSSH>
    
    // 自动连接并执行命令
    autoConnectExecCommand(givenCommand: string,
        options?:SSHExecCommandOptions,
        config?:Config):Promise<SSHExecCommandResponse>
}

Install

$ npm i egg-ssh --save

Usage

// {app_root}/config/plugin.js
exports.ssh = {
  enable: true,
  package: 'egg-ssh',
};

Configuration

链接配置参考 node-ssh

// {app_root}/config/config.default.js
exports.ssh =  {
    host: '127.0.0.1',
    port: '22',
    username: 'root',
    password: 'root',
};

see config/config.default.js for more detail.

Example

ssh 会挂载到app上,可以通过this.app.ssh进行api调用

// 例如
// app/controller/home.js
'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const result = await this.app.ssh.autoConnectExecCommand('expr 1 + 1');
    this.ctx.body = result.stdout;
  }
}

module.exports = HomeController;

Questions & Suggestions

Please open an issue here.

License

MIT

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago