How to use the ssh2.SFTP_STATUS_CODE.PERMISSION_DENIED function in ssh2

To help you get started, we’ve selected a few ssh2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dobbydog / sftp-sync-deploy / lib / sftpSync.ts View on Github external
await Promise.all(files.map(async file => {
        const fullPath = path.posix.join(remotePath, file.filename);
        let stat: SSH2Stats;

        try {
          stat = await this.queuifiedSftp.lstat(fullPath);

          if (stat.isDirectory()) {
            await this.queuifiedSftp.readdir(fullPath);
          } else {
            const buffer = await this.queuifiedSftp.open(fullPath, 'r+');
            await this.queuifiedSftp.close(buffer);
          }
        } catch (err) {
          if (err.code === SFTP_STATUS_CODE.PERMISSION_DENIED) {
            table.set(file.filename, {remoteStat: 'error', remoteTimestamp: null});
          }
          return;
        }

        if (stat) {
          table.set(file.filename, {
            remoteStat: stat.isDirectory() ? 'dir' : 'file',
            remoteTimestamp: stat.mtime
          });
        }
      }));
    };