Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// If the user wants sudo, we'll first convert this shell into a sudo shell
if (config.sftpSudo) await startSudo(shell, config, config.sftpSudo);
shell.write(`echo SFTP READY\n`);
// Wait until we see "SFTP READY" (skipping welcome messages etc)
await new Promise((ready, nvm) => {
const handler = (data: string | Buffer) => {
if (data.toString().trim() !== 'SFTP READY') return;
shell.stdout.removeListener('data', handler);
ready();
};
shell.stdout.on('data', handler);
shell.on('close', nvm);
});
// Start sftpCommand (e.g. /usr/lib/openssh/sftp-server) and wrap everything nicely
const sftps = new SFTPStream({ debug: config.debug });
shell.pipe(sftps).pipe(shell);
const sftp = new SFTPWrapper(sftps);
await toPromise(cb => shell.write(`${cmd}\n`, cb));
return sftp;
}