Search code examples
c#nclam

nclam anti virus is not working with .net application


I am getting this issue: No connection could be made because the target machine actively refused it 127.0.0.1:3310.

using System;
using System.Linq;
using nClam;

class Program
{
    static void Main(string[] args)
    {

        var clam = new ClamClient("localhost", 3310);
        var scanResult = clam.ScanFileOnServer(@"C:\inetpub\wwwroot\rarextract\parts\eicar_com.zip");  //any file you would like!

        switch(scanResult.Result)
        {
            case ClamScanResults.Clean:
                Console.WriteLine("The file is clean!");
                break;
            case ClamScanResults.VirusDetected:
                Console.WriteLine("Virus Found!");
                Console.WriteLine("Virus name: {0}", scanResult.InfectedFiles.First().VirusName);
                break;
            case ClamScanResults.Error:
                Console.WriteLine("Woah an error occured! Error: {0}", scanResult.RawResult);
                break;
        }
    }
}

Solution

  • It looks like you do not have the ClamWin service installed or running on the machine that is executing your code. I wrote some directions a to install it here: http://architectryan.com/2011/05/19/nclam-a-dotnet-library-to-virus-scan/.