简体   繁体   English

将上传的文件作为参数传递给asp.net C#中的.bat文件

[英]Pass uploaded file as argument to .bat file in asp.net c#

I need to run a .bat file in my website that scans files and generate the results to the user. 我需要在网站上运行.bat文件,以扫描文件并向用户生成结果。

Following is the steps that are required to accomplish the task: 1. The user will upload a .zip file by using the FileUpload tool. 以下是完成任务所需的步骤:1.用户将使用FileUpload工具上载.zip文件。 2. The uploaded file will be passed as one of the .bat file arguments in order to scan it. 2.上载的文件将作为.bat文件参数之一传递,以便对其进行扫描。 3. The .bat file will scan the .zip file and then generate the output (new files will be added to the shared folder). 3. .bat文件将扫描.zip文件,然后生成输出(新文件将添加到共享文件夹中)。

I was able to complete step #1 by uploading the file to a shared location. 通过将文件上传到共享位置,我能够完成第1步。 Then I passed the path of the newly uploaded file to the .bat file but no results are shown. 然后,我将新上载的文件的路径传递到.bat文件,但未显示任何结果。

I checked the permissions on the server and granted the website the required access. 我检查了服务器上的权限,并授予网站所需的访问权限。 Also, I installed the latest java version on the server but with no luck. 另外,我在服务器上安装了最新的Java版本,但是没有运气。

The code works perfectly on my local machine but whenever I uploaded to the server it didn't work. 该代码在我的本地计算机上可以正常工作,但是每当我将其上传到服务器时,它都无法正常工作。

string scanFile = @"\\...path..";
string outputLocation = @"\\...path..";
string args = "--project" +name.Text+ "--scan" +scanFile+ "--out" +outputLocation;

//The method that start the process and run .bat file
protected void startP (string path, string args)
{
    Process p = new Process();
    p.StartInfo.FileName = path;
    p.StartInfo.Arguments= args;
    p.StartInfo.UseShellExecute= false;
    p.StartInfo.CreateNoWindow= true;
    p.StartInfo.EnableRaisingEvents= true;
    p.Start();
    p.WaiteForExit();

    if(p.HasExited)
    {
        p.Close();
        // then calling other methods
    }
}

Would you please help me figure out what is the problem? 您能帮我找出问题所在吗? specially that the same exact code run and give the desired output on my local machine but not when I run it through the server ! 特别是在我的本地计算机上运行相同的完全相同的代码并提供所需的输出,但是当我通过服务器运行它时却没有!

NOTE: * The .bat file is uploaded on the server 注意:* .bat文件已上传到服务器上

The core issue is that we do not usually give Webservers the kinds of rights needed for this. 核心问题是我们通常不授予Web服务器为此所需的权利。 Webservers are always on, so they are vulnerable to hacking 24/7. Web服务器始终处于打开状态,因此容易受到24/7黑客攻击。 As a result they are commonly run under a seperate user that just has read rights to the servers Programm and the webpages content diretory - not a single right bit more. 结果,它们通常在单独的用户下运行,该用户仅具有对服务器Programm和网页内容目录的读取权限-一点也不多。

Execution and write rights? 执行权和写权? People will scratch their head why you would even ask for that and then propably keep away from your programm. 人们会挠头为什么你甚至会要求这样做,然后适当地远离程序。 If you give a webserver Write rights you end up with a hacker adding a script that redirects everyone reaching your page via google to a pornographic page (real life example). 如果您授予网络服务器“写”权,您最终将被黑客添加一个脚本,该脚本将通过google到达您网页的所有人重定向到色情网页(现实生活中的示例)。

The thing is also that this this should be unesssesary in 2019. .NET was given the ZipArchive class back in Version 4.5. 同样重要的是,这应该在2019年不再需要。.NET在版本4.5中被赋予了ZipArchive类 And .NET core - comming way after that - had it since 1.0. 而.NET核心-后来的发展-从1.0开始就拥有它。 If you somehow lack it, something is really odd in your scenario. 如果您某种程度上缺少它,那么您的情况中确实有些奇怪。 So you do not need commandline tools for the Unzipping part anyway. 因此,无论如何,您都不需要命令行工具来进行解压缩。

The part of providing files for download is usually done by storing them in/with a DB . 提供文件以供下载的部分通常是通过将文件存储在DB中/中进行的 And then use a HTTP Handler to hand their data out when requested. 然后在请求时使用HTTP处理程序将其数据分发出去。 So again, you can avoid any need for write rights (or at least keep writing contained to the DB Server). 同样,您可以避免任何写权限需求(或至少将写内容保留在DB Server中)。

为什么不尝试在以管理员身份而不是.bat文件运行的Windows Shell脚本中尝试执行此操作?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将上传文件的文件名传递到ASP.NET C#中的SQL值中? - How to pass the file name of an uploaded file into a SQL Value in ASP.NET C#? 如何在ASP.NET C#中执行bat文件并进行跟踪 - How to execute a bat file in ASP.NET C# and trace into it 我想在C#asp.net(mvc)中运行.exe或bat文件 - I want to run .exe or bat file in C# asp.net (mvc) 我在IIS中发布后,在C#ASP.net中执行.Bat文件无法正常工作 - Execute .Bat File in C# ASP.net was not working after I published in IIS ASP.NET上传的文件 - ASP.NET Uploaded File 将通过 HTTP 上传到 ASP.NET 的文件进一步上传到 C# 和 SSH.NET 中的 SFTP 服务器 - Upload file uploaded via HTTP to ASP.NET further to SFTP server in C# and SSH.NET 如何将以HttpPostedFIle形式上传的XML文件转换为C#asp.net中的字符串? - How can I convert a uploaded XML file that is in the form of a HttpPostedFIle to a string in C# asp.net? 将通过 HTTP 上传到 ASP.NET 的文件进一步上传到 C# 中的 FTP 服务器 - Upload file uploaded via HTTP to ASP.NET further to FTP server in C# 我如何在asp.net C#中获取上载文件的源地址 - how can i get the source address of an uploaded file in asp.net c# 文件上传后的C#asp.net异步函数调用 - C# asp.net asynchronous function call after file is uploaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM