Last post Mar 20, 2008 12:08 AM by metascan
Oct 09, 2007 01:32 PM|extremedotnet|LINK
I have an application that allows users to upload files. These files are uploaded and saved to a SQL Server database table (in a field with image data type). Now here's what I would like to do:
When the file is uploaded (and before it's saved on the SQL Server), I would like to check if the file being uploaded (at this point I have a byte of file content) is clear of viruses. And if the file is infected, then I need to notify the user.
Essentially, I would like to call a blackbox API... something like:
bool IsVirusFree(byte dataToScan)
I do not want to save (not even temporarily) the data on the web server (which does have a McAfee AV scanner installed).
What technologies/methodologies are available for .NET to accomplish what I am looking for? Do any Anti-Virus vendors expose such an API?
Jan 03, 2008 03:59 PM|JediKaiti|LINK
Did you ever get an answer to this question? I'd be interested in hearing what you found out.
Jan 03, 2008 04:17 PM|extremedotnet|LINK
No. Although it sounded like some vendors (such as Sophos) do have products that will do it.
In my case, I just ended up writing my own object that exposes the API but it internally relies on (and assumes) a filesystem that is already virus protected... So essentially I try to write the file to a temp location which is virus protected, and if the
write is successful (because the system's anti-virus won't allow if the file is infected), return true, otherwise false.
Jan 03, 2008 05:21 PM|JediKaiti|LINK
Well, that's certainly one way of doing it! I'd be interested in seeing your code for the object, if you're willing to share.
Jan 03, 2008 05:54 PM|extremedotnet|LINK
public class VirusScanner
private string _TemporarySaveDirectory;
private string _FileNamePrependString;
public VirusScanner(string temporarySaveDirectory, string fileNamePrependString)
_TemporarySaveDirectory = temporarySaveDirectory;
_TemporarySaveDirectory = @"C:\Temp";
_TemporarySaveDirectory += @"\";
_FileNamePrependString = fileNamePrependString;
_FileNamePrependString = @"Virus_Scanner_";
public bool IsVirusFree(string fileUniqueID, string fileExtension, string data)
return IsVirusFree(fileUniqueID, fileExtension, data, null);
public bool IsVirusFree(string fileUniqueID, string fileExtension, byte data)
return IsVirusFree(fileUniqueID, fileExtension, string.Empty, data);
private bool IsVirusFree(string fileUniqueID, string fileExtension, string stringData, byte binaryData)
if (string.IsNullOrEmpty(stringData) && binaryData == null)
throw new ArgumentNullException("fileUniqueID");
throw new ArgumentNullException("fileExtension");
string fullFilePathAndName = _TemporarySaveDirectory + _FileNamePrependString + fileUniqueID + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
bool isTextFile = !string.IsNullOrEmpty(stringData);
length = stringData.Length;
StreamWriter sw = File.CreateText(fullFilePathAndName);
length = binaryData.Length;
FileStream fs = File.Create(fullFilePathAndName);
fs.Write(binaryData, 0, binaryData.Length);
FileInfo fi = new FileInfo(fullFilePathAndName);
if (fi.Exists && fi.Length == length)
else if (fi.Exists)
Jan 08, 2008 03:14 PM|JediKaiti|LINK
Jan 18, 2008 02:31 AM|vimoon|LINK
What 's answer for this forum?
Thank a lot.
Mar 20, 2008 12:08 AM|metascan|LINK
You may want to check out OPSWAT Metascan whhich could help you out with the followings:
1) INtegraiton with your antivirus appliciaon
2) Queue Managment
3) Multi scanning technology
4) Optional integrated Ram Drive
LIve demo and source code is avaliable at http://www.filterbit.com/