clamscan icon indicating copy to clipboard operation
clamscan copied to clipboard

NodeClamError: There was an issue scanning the path specified!

Open arthi810 opened this issue 1 year ago • 1 comments

When I run clamscan in the command line, it is able to scan the files in the location. But when I run the below code and pass a file to scan, its failing

const NodeClam = require('clamscan');
const ClamScan = new NodeClam().init({
    clamscan: {
        path: '/usr/local/bin/clamscan'
    },
    clamdscan: {
        path: "/usr/local/bin/clamdscan"
    }
}); 
ClamScan.then(async clamscan => {
        try {
            const pathForFile = __dirname + '/file2.pdf';
            const { path, isInfected, goodFiles, badFiles, viruses } = await clamscan.scanDir(pathForFile);
        } catch (err) {
            console.log({ err })
        }
    }).catch(err => {
        console.log({ err })
    });

Below is the complete error I received

{
  e: NodeClamError: Error: Command failed: /usr/local/bin/clamdscan --no-summary --fdpass --multiscan /Users/mac/Assetplus/insurance-health/src/middlewares/file2.pdf
  
      at parseStdout (/Users/mac/Assetplus/insurance-health/node_modules/clamscan/index.js:1574:83)
      at /Users/mac/Assetplus/insurance-health/node_modules/clamscan/index.js:1602:91
      at ChildProcess.exithandler (node:child_process:410:5)
      at ChildProcess.emit (node:events:513:28)
      at ChildProcess.emit (node:domain:489:12)
      at maybeClose (node:internal/child_process:1100:16)
      at Process.ChildProcess._handle.onexit (node:internal/child_process:304:5) {
    data: { badFiles: [] },
    date: 2024-05-14T07:06:26.161Z
  }
}
{
  err: NodeClamError: There was an issue scanning the path specified!
      at /Users/mac/Assetplus/insurance-health/node_modules/clamscan/index.js:2009:33
      at processTicksAndRejections (node:internal/process/task_queues:96:5) {
    data: {
      path: '/Users/mac/Assetplus/insurance-health/src/middlewares/file2.pdf',
      err: [NodeClamError]
    },
    date: 2024-05-14T07:06:26.163Z
  }
}

Screenshot 2024-05-14 at 12 44 57 PM

arthi810 avatar May 14 '24 07:05 arthi810

You're running scanDir but passing a single file. Use isInfected, instead, if you want to scan a single file. Or pass the directory you want to scan (ex. /Users/mac/Assetplus/insurance-health/src/middlewares)

kylefarris avatar May 14 '24 15:05 kylefarris