上传文件病毒扫描 [英] Upload a file virus scanning

查看:550
本文介绍了上传文件病毒扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传文件病毒扫描



我尝试过:



i want to upload a file virus scanning

What I have tried:

public void scanfile()
   {
       string c;
           bool IsValid = true;
       //foreach (FileInfo file in fileuploadExcel.Unload)
       //{
       try
       {
           //do av check here
           Process myProcess = new Process();
           FileUpload1.SaveAs(Server.MapPath("~\\uploadphoto\\") + FileUpload1.FileName);
           //address of command line virus scan exe
           myProcess.StartInfo.FileName = Server.MapPath("~\\AVG10\\avgscanx.exe");


           string path = '"' + "" + Server.MapPath("~\\uploadphoto\\") + "" + FileUpload1.FileName + "" + '"';
           string report = '"' + "" + Server.MapPath("~\\uploadphoto\\Report.txt") + "" + '"';
           string myprocarg = "/SCAN=" + path + " /REPORT=" + report;
           //" /REPORT=C:\\Upload\\Temp\\Report.txt";
           myProcess.StartInfo.Arguments = myprocarg;
           myProcess.StartInfo.UseShellExecute = false;
           myProcess.StartInfo.RedirectStandardOutput = true;

           myProcess.Start();
           myProcess.WaitForExit(); //wait for the scan to complete
                                    //add some time for report to be written to file
           int j = 0;
           int y = 0;
           for (j = 0; j <= 1000000; j++)
           {
               y = y + 1;
           }
           //Get a StreamReader class that can be used to read the file
           StreamReader objStreamReader = default(StreamReader);
           objStreamReader = File.OpenText(Server.MapPath("~\\VirusScan\\Report.txt"));
           String reportVerbose = objStreamReader.ReadToEnd().Trim();
           if (reportVerbose.Length > 0 && !reportVerbose.Contains("Found infections    :    0"))
           {
               IsValid = false;
               File.Delete(Server.MapPath("~\\VirusScan\\temp\\") + "" + FileUpload1.FileName);
           }
           objStreamReader.Close();
           if (IsValid)
           {
               try
               {
                   if (!Directory.Exists(Server.MapPath("~/DataFiles/")))
                       Directory.CreateDirectory(Server.MapPath("~/DataFiles/"));
                   if (!File.Exists(Server.MapPath("~/DataFiles/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))))
                   {
                       FileUpload1.SaveAs(Server.MapPath("~/DataFiles/") + FileUpload1.FileName);
                   }
                   else
                   {
                       try
                       {
                           File.Delete(Server.MapPath("~/DataFiles/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)));
                           FileUpload1.SaveAs(Server.MapPath("~/DataFiles/") + FileUpload1.FileName);
                       }
                       catch (System.IO.IOException)
                       {

                       }
                   }
               }
               catch (System.IO.IOException)
               {

               }

           }
       }
       catch (System.IO.IOException)
       {

       }

推荐答案

你的确切问题是什么?



一些常规提示:
  • 报告错误。捕获异常而不报告错误并没有多大帮助。特别是在开发期间,错误消息将告诉您出了什么问题,因此在大多数情况下不需要调试会话。

  • 分别测试每个任务。从上传开始。文件已上传吗?

  • 检查你的病人:AV扫描仪是否位于网络服务器目录 Server.MapPath(〜\\AVG10 \\ avgscanx.exe)?可能不是。

  • 检查您的路径:您已将报告路径设置为〜\\uploadphoto \\Report.txt但尝试阅读报告来自〜\\VirusScan \\Report.txt。

  • 使用 EICAR测试文件 - 维基百科 [ ^ ]存储在知道位置。

And what is your exact problem?

Some general tips:
  • Report errors. Catching exceptions without reporting errors does not really help. Especially during development the error messages will tell you what went wrong so that there is no need for debugging sessions in most cases.
  • Test each of your tasks separately. Start with uploading. Is the file uploaded?
  • Check your pathes: Is the AV scanner located in the web server directory Server.MapPath("~\\AVG10\\avgscanx.exe")? Probably not.
  • Check your pathes: You have set the report path to "~\\uploadphoto\\Report.txt" but trying to read the report from "~\\VirusScan\\Report.txt".
  • Check the scanning using an EICAR test file - Wikipedia[^] stored at a know location.


这篇关于上传文件病毒扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆