当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ssh2.on函数代码示例

本文整理汇总了TypeScript中ssh2.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了on函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: writeFile

  writeFile (options: any, file: any) {

    const conn = new ssh2(),
          deferred = this.deferred(),
          limit = 20;

    options.attempts = 0;

    conn.on('ready', () => {
      conn.sftp((err, sftp) => {

        const writeStream = sftp.createWriteStream(file.path);
        const readStream = new Readable();
        readStream.push(file.content);
        readStream.push(null);

        writeStream.on('close', () => {
          conn.end();
          deferred.resolve(file.path);
        });

        readStream.pipe(writeStream);
      });

    }).on('error', (err) => {
      if (options.attempts > limit) {
        deferred.reject(err);
      }
      options.attempts++;
      conn.connect(options);
    });

    conn.connect(options);
    return deferred.promise;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:35,代码来源:SFTP.ts

示例2: moveFile

  moveFile (fromPath: string, toPath: string, options: any) {

    const conn = new ssh2(),
          deferred = this.deferred(),
          limit = 20;
    options.attempts = 0;

    conn.on('ready', () => {

      conn.sftp((err, sftp) => {
        if (err) deferred.reject(err);
        sftp.rename(fromPath, toPath, (err, response) => {
          if (err) {
            deferred.reject(err);
          }
          sftp.end();
          deferred.resolve(response);
        });
      });

    }).on('error', (err) => {

      if (options.attempts > limit) {
        deferred.reject(err);
      }
      options.attempts++;
      conn.connect(options);
      
    });
    conn.connect(options);
    return deferred.promise;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:32,代码来源:SFTP.ts

示例3: connect

  connect (options: any, callback: any) {

    const me = this,
          conn = new ssh2();

    conn.on('ready', () => {
      conn.sftp((err, sftp) => {
        callback(err, sftp);
      });
    });

    conn.connect(options);

  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:14,代码来源:SFTP.ts

示例4: play

export function play(monogatari: string, options: PlayOptions) {

  if (!fs.existsSync(options.hostsfile)) {
    log.error('play', `${options.hostsfile} does not exists`);
    process.exit(1);
  }

  const cwd: string = process.cwd();
  monogatari = path.resolve(cwd, 'monogatari', monogatari);
  const hostsfile  = path.resolve(cwd, options.hostsfile);

  const hosts       = yaml.safeLoad(fs.readFileSync(hostsfile, 'utf8'))[0];
  const monogataris = yaml.safeLoad(fs.readFileSync(monogatari, 'utf8'))[0];

  console.log(hosts);
  console.log(monogataris);

  //TODO: update .d.ts of ssh2 and send PR
  const client = new Connection();

  client.on('ready', () => {
    log.info('play', 'connected');

    client.exec(monogataris.tasks[0].shell, (err, stream) => {
      if(err) {
        throw err;
      }

      stream.on('close', (code, signal) => {
        log.info('play', `end code:${code}, signal:${signal}`);
        client.end();
      })
      .on('data', data => {
        log.info('play', data);
      })
      .stderr.on('data', data => {
        log.error('play', data);
      });

    });
  })
  .connect({
    host: hosts[monogataris.hosts].host,
    port: hosts[monogataris.hosts].port,
    username: hosts[monogataris.hosts].user,
    privateKey: fs.readFileSync(options.privateKey)
  });
}
开发者ID:waffle-iron,项目名称:shikibu,代码行数:48,代码来源:play.ts

示例5: readFile

  readFile (options: any, file: any) {

    const conn = new ssh2(),
          deferred = this.deferred(),
          limit = 20;

    options.attempts = 0;

    conn.on('ready', () => {

      conn.sftp((err, sftp) => {
        const stream = sftp.createReadStream(file.path);

        let content = "";

        stream.on('data', (chunk) => {
          content += chunk;
        }).on('end', () => {
          conn.end();
          deferred.resolve(content);
        }).on('error', (err) => {
          sftp.end();
          deferred.reject(err);
        });

      });

    }).on('error', (err) => {
      if (options.attempts > limit) {
        deferred.reject(err);
      }

      options.attempts++;
      conn.connect(options);
    });

    conn.connect(options);
    return deferred.promise;
  }
开发者ID:chrisk-symphony,项目名称:sy-trans,代码行数:39,代码来源:SFTP.ts


注:本文中的ssh2.on函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。