Skip to content

Instantly share code, notes, and snippets.

@TimothyODonnell
Forked from shinkathe/Run clamAV.cs
Created November 11, 2022 14:18
Show Gist options
  • Save TimothyODonnell/22eb0e615148fb264a12f47c44cfe172 to your computer and use it in GitHub Desktop.
Save TimothyODonnell/22eb0e615148fb264a12f47c44cfe172 to your computer and use it in GitHub Desktop.
// ##### RUN AV ON FILE #####
log.LogInformation("Download completed. Connecting to AV server {ClamAVServerUrl}:{ClamAVServerPort}... ", ClamAVServerUrl, ClamAVServerPort);
var clam = new ClamClient(ClamAVServerUrl, ClamAVServerPort);
bool isConnected = await clam.PingAsync();
var version = await clam.GetVersionAsync();
if (!isConnected) throw new Exception("AV server connection could not be established.");
log.LogInformation("Connection ok: {IsConnected}. AV server reports version: {ServerVersion}", isConnected, version);
var scanResult = await clam.SendAndScanFileAsync(ms.ToArray());
switch (scanResult.Result)
{
case ClamScanResults.Clean:
log.LogInformation("The file is clean!");
// Continue
break;
case ClamScanResults.VirusDetected:
log.LogCritical("Virus found. Deleting file.");
await blobClient.DeleteIfExistsAsync(Azure.Storage.Blobs.Models.DeleteSnapshotsOption.IncludeSnapshots);
// Do other steps
break;
case ClamScanResults.Error:
default:
log.LogInformation("File scan error occurred. {ScanResult}", scanResult.RawResult);
break;
}
@shinkathe
Copy link

I have linked this discussion in my post to the part where these settings were discussed and improved that bit slightly. Thanks @TimothyODonnell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment