How to use the ssh2.Client function in ssh2

To help you get started, we’ve selected a few ssh2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sungshon / PimpMyStremio / src / lib / tunnels / serveo.js View on Github external
function runTunnel(pmsPort, remoteOpts) {

    // Create a SSH client
    const conn = new Client();

    const config = {
      remoteHost: remoteOpts.subdomain || '',
      remotePort: 80,
      localHost: 'localhost',
      localPort: pmsPort
    }

    conn
      .on('error', err => {
        if (err)
            console.error(err)
        console.log('Serveo - Got error from tunnel, restarting connection in 5 seconds')
        setTimeout(() => {
            runTunnel(pmsPort, remoteOpts)
        }, 5000)
github lholoubek / solo-toolkit / static / js / Device.js View on Github external
super();
    var self = this;
    //self = this;
    this.controllerConnected = false;
    this.soloConnected = false;
    this.versions = {
      sololink_version: " – ",
      gimbal_version: " – ",
      ak_version: " – ",
      shotmanager_version: " – ",
      pixhawk_version: " – ",
      controller_version: " – ",
      ssid: " – ",
      password: " – "
    }
    this.controller_connection = new Client();
    this.solo_connection = new Client();


// Controller connection config
    this.controller_connection_params = {
        host: '10.1.1.1',
        port: 22,
        username: 'root',
        password: 'TjSDBkAu',
        readyTimeout: 2000,
        keepaliveInterval: 2000
    }

    this.controller_connection.on('ready', function(er) {
        if(er){
          Logger.log("Connection ready but error with controller");
github EvHaus / rocketry / src / run.js View on Github external
return new Promise((resolve, reject) => {
			let privateKey;
			try {
				privateKey = fs.readFileSync(private_key_path);
			} catch (err) {
				throw new Error(
					`Can't find private SSH key in ${chalk.yellow(private_key_path)}. ` +
					`Make sure you're running this script via Bash.`
				);
			}

			const c = new Client();
			c.on('ready', () => {
				spinner.succeed(`Connected to ${chalk.yellow(host)}`);
				resolve(c);
			}).connect({
				host,
				username: user,
				privateKey,
				passphrase: this.sshPassword,
			});
		}).catch((err) => {
			// ssh2 reports wrong password as "InvalidAsn1Error"
github lholoubek / solo-toolkit / build / js / state.js View on Github external
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(Device).call(this));

    var self = _this;
    //self = this;
    _this.controllerConnected = false;
    _this.soloConnected = false;
    _this.versions = {
      solo_version: " – ",
      gimbal_version: " – ",
      pixhawk_version: " – ",
      controller_version: " – ",
      ssid: " – ",
      password: " – "
    };
    _this.controller_connection = new Client();
    _this.solo_connection = new Client();

    _this.controller_connection_params = {
      host: '10.1.1.1',
      port: 22,
      username: 'root',
      password: 'TjSDBkAu',
      readyTimeout: 2000
    };

    _this.controller_connection.on('ready', function (er) {
      if (er) {
        console.log("Connection ready but error with controller");
      } else {
        console.log('Controller :: ready');
        self.controllerConnected = true;
        successConnectCallback("controller");
github IBMStreams / streamsx.health / dashboard / server / models / streamtool.js View on Github external
Streamtool.prototype.connect = function(params) {
  var self = this;
  this.conn = new ssh.Client();
  this.sshParams = params
  this.instanceName = params['instanceName']
  this.domainName = params['domainName']
  this.restURL = "https://" + this.sshParams.host + ":" + this.sshParams.apiPort + "/streams/rest";

  this.conn.on('error', function(err) {
    self.emit('error', err);
  })

  this.conn.on('ready', function() {
    self.emit('ready');
  }).connect({
    host: this.sshParams.host,
    port: this.sshParams.port,
    username : this.sshParams.username,
    password : this.sshParams.password
github ottomatica / Baker / lib / modules / ssh.js View on Github external
return new Promise((resolve, reject) =>
        {
            const client = new Client();
            client.on("ready", () => {
                client.exec(cmd, function (err, stream){
                    console.log(`Issued ${cmd}`);
                    stream.on('close', function (code, signal)
                    {
                        setTimeout(function(){
                            client.end();
                            resolve(code);
                        }, 500);
                    })
                    .on('data', function (data) {
                    })
                    .stderr.on('data', function(data)
                    {
                        reject(data);
                    });
github brainfoolong / web-ftp-client / src / ftpServer.js View on Github external
})
    }
    if (serverData.protocol === 'sftp') {
      const connectData = {
        host: serverData.host,
        port: serverData.port
      }
      connectData.username = serverData.username
      if (serverData.auth === 'normal') {
        connectData.password = aes.decrypt(salt + '_' + serverData.id, serverData.password)
      }
      if (serverData.auth === 'keyfile') {
        connectData.privateKey = serverData.keyfile.trim()
        connectData.passphrase = aes.decrypt(salt + '_' + serverData.id, serverData.keyfile_passphrase)
      }
      self.sshClient = new SshClient()
      self.sshClient.on('ready', function () {
        self.server.log('log.ftpserver.ready')
        self.sshClient.sftp(function (err, sftp) {
          if (err) {
            self.server.logError(err)
            callback(false)
            self.disconnect()
            return
          }
          self.server.log('log.ftpserver.sftpready')
          self.sftp = sftp
          self.sftp.highWaterMark = 5 * 1024 * 1024
          callback(true)
        })
      }).on('error', function (err) {
        self.disconnect()
github kooohei / brackets-synapse / node / SynapseDomain.js View on Github external
sftpResolveEntity = function (setting, remotePath) {
			var	con = new SFTP();
			var masterQ = Q.defer();
		
			function stat(sftp, ent) {
				var q = Q.defer(),
						stats = ent.attrs;
				
				if (stats.isDirectory()) {
					ent.type = "d";
					q.resolve(ent);
				} else
				if (stats.isFile()) {
					ent.type = "-";
					q.resolve(ent);
				} else
				if (stats.isSymbolicLink()) {
					ent.type = "l";
github Dyalog / ride / src / proxy.js View on Github external
,sshExec=(x,cmd,f)=>{ //f:callback
  try{ //see https://github.com/mscdex/ssh2/issues/238#issuecomment-87495628 for why we use tryKeyboard:true
    var c=new(require('ssh2').Client),o={host:x.host,port:x.port,username:x.user,tryKeyboard:true}
    x.key?(o.privateKey=fs.readFileSync(x.key)):(o.password=x.pass)
    c.on('ready',_=>{c.exec(cmd,(e,sm)=>{e||f(sm)})})
     .on('tcp connection',(_,acc)=>{clt=acc();iSend('*connected',{host:'',port:0});initInterpreterConn()})
     .on('keyboard-interactive',(_,_1,_2,_3,fin)=>{fin([x.pass])})
     .connect(o)
  }catch(e){iSend('*error',{msg:e.message})}
  return c
}
module.exports=x=>{