Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const files = fs.readdirSync(localPath);
if (files && files.length) {
await Promise.all(
files.map(filename => this.upload(path.posix.join(relativePath, filename), false))
);
}
} else {
try {
// const buffer = fs.readFileSync(localPath);
// const handle = await this.queuifiedSftp.open(remotePath, 'r+');
// await this.queuifiedSftp.writeData(handle, buffer, 0, buffer.length, 0);
// await this.queuifiedSftp.close(handle);
await this.queuifiedSftp.fastPut(localPath, remotePath);
} catch (err) {
switch (err.code) {
case SFTP_STATUS_CODE.NO_SUCH_FILE: {
throw new Error(`Remote Error: Cannot upload file ${remotePath}`);
}
case SFTP_STATUS_CODE.PERMISSION_DENIED: {
throw new Error(`Remote Error: Cannot upload file. Permission denied ${remotePath}`);
}
case SFTP_STATUS_CODE.FAILURE: {
throw new Error(`Remote Error: Unknown error while uploading file ${remotePath}`);
}
default: throw err;
}
}
}
if (isRootTask) this.close();
}
.catch((e) => {
if(e.code === 'ENOENT')
sftpStream.status(reqid, SFTP_STATUS_CODE.NO_SUCH_FILE);
else
sftpStream.status(reqid, SFTP_STATUS_CODE.FAILURE);
});
})
.catch((err) => sftpStream.status(reqid, SFTP_STATUS_CODE.NO_SUCH_FILE))
.then((stats) => sftpStream.attrs(reqid, stats));