本文整理汇总了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;
}
示例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;
}
示例3:
}).on('error', (err) => {
if (options.attempts > limit) {
deferred.reject(err);
}
options.attempts++;
conn.connect(options);
});
示例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);
}
示例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;
}
示例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;
}