本文整理匯總了TypeScript中ssh2-sftp-client.list函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript list函數的具體用法?TypeScript list怎麽用?TypeScript list使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了list函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: readdirRemote
/**
* Gets the list of files in the remote directory recursively.
*
* @param sftp
* The SFTP client.
* @param remotePath
* The remote directory.
*
* @returns
* A Promise that resolved with the list of remote files.
*/
async function readdirRemote(sftp: SftpClient, remotePath: string): Promise<string[]> {
const files: string[] = []
const remoteFiles = await sftp.list(remotePath)
for (const remoteFile of remoteFiles) {
const remoteFilePath = path.posix.join(remotePath, remoteFile.name)
switch (remoteFile.type) {
case '-':
files.push(remoteFilePath)
break
case 'd':
files.push(...await readdirRemote(sftp, remoteFilePath))
break
}
}
return files
}
示例2: Client
import * as Client from 'ssh2-sftp-client';
var client = new Client();
client.connect({
host: 'asdb',
port: 1234,
privateKey: 'my private key rsa in openssh format',
readyTimeout: 1000,
}).then(() => null);
client.list('/remote/path').then(() => null);
client.get('/remote/path').then(stream => stream.read(0));
client.put('/local/path', '/remote/path').then(() => null);
client.put(new Buffer('content'), '/remote/path').then(() => null);
client.mkdir('/remote/path/dir', true).then(() => null);
client.delete('remote/path').then(() => null);
client.rename('/remote/from', '/remote/to').then(() => null);
client.end().then(() => null);