我目前正在使用
shelljs
在每次需要使用ssh功能时建立连接。
class Connection {
constructor(id, path) {
this.id = id;
this.path = path;
}
exec(silent, ...args) {
const { exec } = shellJS;
const execCmd = exec(
['ssh ', ...args].join(' '),
{ silent }
);
// FormError(execCmd);
return execCmd;
}
}
class FileManager {
constructor(connection) {
this.connection = connection;
}
async ls(path = '') {
const newPath = path ? `'${path}/'` : '';
const listing = this.connection.exec(false, `"ls -l ${newPath}"`);
return parseEntries(listing.stdout);
}
}
EDIT1:布拉德回答后,安装可能无法在这里工作,因为
这里的代码有些简化。真正的流程是:
Local -> SSH Server
-> AnAppThatManagesCloudBuckets <command>
-> Output