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


TypeScript ssh2.connect函数代码示例

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


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

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

示例4: 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

示例5: readDir

  readDir (options: any, file: any) {

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

    conn.connect((err, sftp) => {
      if (err) deferred.reject(err);

      sftp.readdir(file.path, (err, list) => {
        if (err) deferred.reject(err);

        sftp.end();
        deferred.resolve(list);
      });
    });

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

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