diff --git a/lib/client.js b/lib/client.js index 3e393e50..0c880c82 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1554,7 +1554,7 @@ class Client extends EventEmitter { return this; } - sftp(cb) { + sftp(cb, { command } = {}) { if (!this._sock || !isWritable(this._sock)) throw new Error('Not connected'); @@ -1564,7 +1564,7 @@ class Client extends EventEmitter { return; } - reqSubsystem(sftp, 'sftp', (err, sftp_) => { + const sftpCb = (err, sftp_) => { if (err) { cb(err); return; @@ -1610,7 +1610,13 @@ class Client extends EventEmitter { .on('close', onExit); sftp._init(); - }); + }; + + if (command) { + reqExec(sftp, command, {}, sftpCb); + } else { + reqSubsystem(sftp, 'sftp', sftpCb); + } }); return this;