12

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

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

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

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

4

2 回答 2

4

首先,您必须检查您安装的防病毒软件提供了什么样的 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

希望这对您有所帮助。

于 2016-12-08T06:29:00.507 回答
2

在线 AntiVirus ClamAV:https ://github.com/cdarras/clamav-client是一个不错的选择。

如果你使用 Linux/Mac,在线 AV 应该足够了。如果您使用 Windows,您还应该在您的服务器上安装防病毒软件。

于 2018-04-12T09:30:14.410 回答