本文整理汇总了TypeScript中ssh2-sftp-client.end函数的典型用法代码示例。如果您正苦于以下问题:TypeScript end函数的具体用法?TypeScript end怎么用?TypeScript end使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了end函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
//.........这里部分代码省略.........
type: 'password'
}
])
const { username, password } = answers
const sftp = new SftpClient()
const createQueue = async.queue<CreatePayload, Error>(({ observer, remotePath, title }, callback) => {
createQueue.drain = () => observer.complete()
observer.next(title)
sftp.mkdir(remotePath, true).then(() => callback()).catch(callback)
})
const uploadQueue = async.priorityQueue<UploadPayload, Error>(({ localPath, observer, remotePath, title }, callback) => {
uploadQueue.drain = () => observer.complete()
const remainingCount = uploadQueue.length()
const inProgressTitles = uploadQueue.workersList()
.map(worker => worker.data.title)
.sort()
.map(title => title.length <= 27 ? title : `${title.substr(0, 12)}...${title.slice(-12)}`)
const message = inProgressTitles.join(', ') + (remainingCount ? ` + ${remainingCount} more` : '')
observer.next(message)
sftp.put(localPath, remotePath, true).then(() => callback()).catch(callback)
}, 4)
const deleteQueue = async.queue<DeletePayload, Error>(({ observer, remotePath, title }, callback) => {
deleteQueue.drain = () => observer.complete()
observer.next(title)
sftp.delete(remotePath).then(() => callback()).catch(callback)
})
try {
await sftp.connect({ host: HOST, username, password })
const [localFiles, remoteFiles] = await Promise.all([
(await readdir('dist')).map(file => path.relative('dist', file)).map(file => path.posix.format(path.parse(file))),
(await readdirRemote(sftp, DEPLOY_DIR)).map(file => path.posix.relative(DEPLOY_DIR, file)),
])
const remoteFilesToDelete = getRemoteFilesToDelete(remoteFiles, localFiles)
const remoteDirectoriesToCreate = getRequiredDirectories(localFiles)
const createObserver = new Observable<string>(observer => {
for (const directory of remoteDirectoriesToCreate) {
const remotePath = path.posix.join(DEPLOY_DIR, directory)
createQueue.push({ observer, remotePath, title: directory })
}
})
const uploadObserver = new Observable<string>(observer => {
for (const file of localFiles) {
const localPath = path.resolve(path.join('dist', file))
const remotePath = path.posix.join(DEPLOY_DIR, file)
const payload: UploadPayload = {
localPath,
observer,
remotePath,
title: file,
}
uploadQueue.push(payload, getUploadPriority(file))
}
})
const deleteObserver = new Observable<string>(observer => {
for (const file of remoteFilesToDelete) {
const remotePath = path.posix.join(DEPLOY_DIR, file)
deleteQueue.push({ observer, remotePath, title: file })
}
})
await new Listr([
{
title: `Creating ${remoteDirectoriesToCreate.length} Directories`,
task: () => createObserver as any,
skip: () => remoteDirectoriesToCreate.length === 0 ? 'No directories to create' : '',
},
{
title: `Uploading ${localFiles.length} File(s)`,
task: () => uploadObserver as any,
skip: () => localFiles.length === 0 ? 'No files to upload' : '',
},
{
title: `Deleting ${remoteFilesToDelete.length} File(s)`,
task: () => deleteObserver as any,
skip: () => remoteFilesToDelete.length === 0 ? 'No files to delete' : '',
},
]).run()
await sftp.end()
console.log('Done')
} catch (err) {
console.log(err)
}
process.exit(0)
}())
示例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);