Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} 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);
});
})