當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。