java - 检查上传的文件是否有病毒

标签 java antivirus antivirus-integration

我有一些申请。用户可以上传文件,我将其保存在磁盘上,并在用户需要时返回。我需要对上传的文件实现一些病毒保护。 我为这个问题找到了 3 个解决方案:

  1. 使用在线防病毒软件
  2. 在我的服务器上安装防病毒软件并从命令行检查上传的文件
  3. 通过 sdk 或 api 集成防病毒。

我不喜欢第一个解决方案,因为我将我的文件和私有(private)信息发送给其他服务器。 我认为第二种解决方案是最好的,但我不知道如何正确实现它。 最后一个解决方案很好,但我找不到任何有 java api 的好的和著名的防病毒软件。

请给我一些解决这个问题的方向。 mb 一些建议或文献。 解决它的最佳方法是什么?

最佳答案

首先,您必须检查您安装的杀毒软件提供了什么样的API。

如果提供了任何 Java API(如 AVG API),那么您必须按如下方式使用它:

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.");
      }
   }
}

如果安装的杀毒软件没有提供Java API,那么您仍然可以使用命令行调用它,如下所示:

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);

有一篇有趣的文章供您引用:Implementing an Anti-Virus File Scan in JEE Applications

希望对你有帮助。

关于java - 检查上传的文件是否有病毒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38562418/

相关文章:

java - 是否可以从 java.sql.Connection 获取 url 或服务器信息

java - If 语句最佳实践

c++ - 运行最简单的 C++ 程序时出现 AVG Access Denied 警告

windows-xp - 我如何告诉 "windows security center"我是 "antivirus"?

java - 使用 JAVA 从命令行运行 Symantec End Point DoScan.exe

java - 如何解决Java Collections.sort() Comparison方法违反其一般契约异常

java - Java中如何将数组转换为集合?

.net - 与 .net 应用程序的防病毒集成

c# - 请帮助我使用检测恶意行为的病毒检测程序

web-services - 像 Virus Total 这样的网站是如何运作的?