本文整理汇总了TypeScript中ssh2.Client.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Client.on方法的具体用法?TypeScript Client.on怎么用?TypeScript Client.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ssh2.Client
的用法示例。
在下文中一共展示了Client.on方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Client
socks.createServer( (info: any, accept: any, deny: any) => {
// NOTE: you could just use one ssh2 client connection for all forwards, but
// you could run into server-imposed limits if you have too many forwards open
// at any given time
var conn = new Client();
conn.on('ready', () => {
conn.forwardOut(info.srcAddr,
info.srcPort,
info.dstAddr,
info.dstPort,
(err: Error, stream: ssh2.ClientChannel) => {
if (err) {
conn.end();
return deny();
}
var clientSocket: any;
if (clientSocket = accept(true)) {
stream.pipe(clientSocket).pipe(stream).on('close', () => {
conn.end();
});
} else
conn.end();
});
}).on('error', (err: Error) => {
deny();
}).connect(ssh_config);
}).listen(1080, 'localhost', () => {
示例2: Client
return new Promise<PromiseSFTP>((resolve, reject) => {
const client = new Client();
client.on("error", reject);
client.on("ready", () => {
client.sftp((err: Error, sftp: SFTPWrapper) => {
if (err) {
reject(err);
}
resolve(new PromiseSFTP(sftp, client));
});
});
client.connect(config);
});
示例3: setupSshClientConnection
export function setupSshClientConnection(sshConfig: any) : Q.Promise<any> {
var defer = Q.defer<any>();
var client = new Ssh2Client();
client.on('ready', () => {
defer.resolve(client);
}).on('error', (err) => {
defer.reject(err);
}).connect(sshConfig);
return defer.promise;
}
示例4: initialize
function initialize() {
conn = new Client();
conn.on('ready', function () {
console.log('conn::ready');
conn.exec('gerrit stream-events', function (err, stream) {
console.log('gerrit stream-events');
if (err) {
console.log('gerrit stream-events error', err);
return reConnect();
}
stream.on('close', () => {
console.log('stream::close');
});
stream.on('error', (err) => {
console.log('stream::error', err);
});
stream.on('data', (data) => {
console.log('stream::data', data + '');
pushData(data);
});
});
});
conn.on('close', (hadError) => {
console.log('conn::close');
});
conn.on('end', () => {
console.log('conn::end');
});
conn.on('error', (err) => {
console.log('conn::error', err + '');
conn.end();
reConnect();
});
connect();
}
示例5: cleanupTable
function cleanupTable(resolve, reject) {
var conn = new Client();
conn.on('ready', function() {
console.log(chalk.bold.green('Connected to node1 as root'));
conn.shell(function(err, stream) {
if (err) throw err;
stream.on('close', function() {
if (errorMsg.length > 0) {
console.log(chalk.bold.red('Error is:') + errorMsg);
console.log(chalk.red.bgBlack.bold('Unable to truncate metron_update table in HBase. Most likely reason is HBase is down !!!'));
reject();
} else {
console.log(chalk.bold.green('Truncated metron_update table in HBase'));
resolve();
}
conn.end();
}).on('data', function(data) {
console.log('STDOUT: ' + data);
if (data.indexOf('ERROR') !== -1) {
errorMsg = data;
}
}).stderr.on('data', function(data) {
console.log('STDERR: ' + data);
});
var comands = [
'echo \'truncate "metron_update"\' | /usr/hdp/current/hbase-master/bin/hbase shell',
'exit',
''
];
stream.end(comands.join('\r\n'));
});
}).connect({
host: 'node1',
port: 22,
username: 'root',
password: 'vagrant'
});
}
示例6: require
// # Client Examples
//
// Authenticate using keys and execute uptime on a server:
var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', () => {
console.log('Client :: ready');
conn.exec('uptime', (err: Error, stream: ssh2.ClientChannel) => {
if (err) throw err;
stream
.on('close', (code: any, signal: any) => {
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
conn.end();
}).on('data', (data: any) => {
console.log('STDOUT: ' + data);
}).stderr.on('data', (data: any) => {
console.log('STDERR: ' + data);
});
});
}).connect({
host: '192.168.100.100',
port: 22,
username: 'frylock',
privateKey: require('fs').readFileSync('/here/is/my/key')
});
// Authenticate using keys and start an interactive shell session: