我有一些申请。用户可以上传文件,我将其保存在磁盘上,并在用户需要时将其返回。我需要为上传的病毒文件实施一些保护。 我找到了3个解决这个问题的方法:
我不喜欢第一个解决方案,因为我发送我的文件和其他服务器的私人信息。 我认为最好的第二个解决方案,但我不知道如何正确实现它。 最后的解决方案很好,但我找不到任何有着java api的好的和着名的防病毒软件。
请给我一些方向来解决这个问题。有些建议或文献。 什么是解决它的最佳方法?
答案 0 :(得分:2)
首先,您必须检查已安装的防病毒软件提供的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);
有一篇有趣的文章供您参考:在JEE应用程序中实施反病毒文件扫描
希望这会对你有所帮助。
答案 1 :(得分:0)
在线AntiVirus ClamAV:https://github.com/cdarras/clamav-client是一个很好的。
如果使用Linux / Mac,在线AV就足够了。 如果您使用Windows,还应该在服务器上安装防病毒软件。