egg-ssh
v1.0.5
Published
egg 插件 基于ssh2
Downloads
2
Maintainers
Readme
egg-ssh
一款基于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.