我正在开发一个需要文件上传的应用程序,它还需要在服务器上使用可用的防病毒软件扫描该文件.
我听说赛门铁克为应用服务器提供了APIS.
Situatuion就像,我需要在将来在不同的地方部署应用程序.所以,我正在考虑放置一个配置文件,从我将要获取可用的Antivirus及其路径.
我想在服务器上使用任何可用的防病毒软件,然后使用命令行,我想传回文件名和结果.
我很困惑在传递文件和检索结果.
可能吗?
使用以下代码.
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);
Run Code Online (Sandbox Code Playgroud)
Commnad线对你来说是更好的选择.然后读取日志文件来解决问题.
我只是google了一下,发现一篇有趣的文章在这里看看
要在Java中实现病毒文件扫描,需要使用第三方软件包.出于本文的目的,我将使用随Java API一起提供的Symantec Scan Engine(SSE)程序包.该软件包是一个用作TCP/IP服务器的应用程序,具有编程接口,使Java应用程序能够包含对内容扫描技术的支持.在本文中,我使用了Symantec Scan Engine 5.1,它可以作为Unix或Windows安装使用.
快速参考:
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.");
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后
catch (Exception ex) {
logger.error(ex);
if (ex instanceof VirusException) {
// do something here
}
else {
// there was some other error – handle it
}
}
Run Code Online (Sandbox Code Playgroud)