Scan downloaded files for viruses

I have an application. The user can download files, save them to disk and return when the user wants. I need to implement some protection for downloaded files for viruses. I found 3 solutions to this problem:

  • Use online antiviruses
  • Install antivirus on my server and check the downloaded file from the command line
  • Antivirus integration using sdk or api.

I do not like the first solution, because I send my files and private information to another server. The second solution, which I consider the best, but I do not know how to implement it correctly. The latter solution is good, but I can not find any good and well-known antiviruses that have java api.

Please give me some solution to solve this problem. MB some advice or literature. What is the best way to solve it?

+6
source share
1 answer

First, you should check which API your installed antivirus software provides.

If there is any Java API (e.g. AVG API), you should use it as shown below:

public void scanFile(byte[] fileBytes, String fileName) throws IOException, Exception { if (scan) { AVClient avc = new AVClient(avServer, avPort, avMode); if (avc.scanfile(fileName, fileBytes) == -1) { throw new VirusException("WARNING: A virus was detected in your attachment: " + fileName + "<br>Please scan your system with the latest antivirus software with updated virus definitions and try again."); } } } 

If antivirus software is not provided by the Java API, you can invoke it using the command line, as shown below:

 String[] commands = new String[5]; commands[0] = "cmd"; commands[1] = "/c"; commands[2] = "C:\\Program Files\\AVG\\AVG10\\avgscanx.exe"; commands[3] = "/scan=" + filename; commands[4] = "/report=" + virusoutput; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(commands); 

There is an interesting article for reference: Implementing Antivirus File Scanning in JEE Applications

Hope this helps you.

+2
source

All Articles