Detailed explanation of web-based file transfer solutions in the LAN

zhaozj2021-02-11  184

Author: tonnyEMAIL: webmaster@weiw.com reprint please show the source: http: //www.weiw.com

Environmental description:

Two servers in the LAN, a main web server, a file server, two server operating system for Win2000 Professional (or win2000 server) main web server LAN internal URL: http: // main: 8080 external URL server The computer name is: the port of the main Web site is 8080

Document server LAN internal URL: http: // file: 8080 server computer name: port of File Web site is 8080

Demand introduction: Visitors Access the web server and place the file in the file server when uploading the file, such as generating some information, and is generated on the file server. The web server does not retain file replica. And allow files to generate an ASPX format.

Workaround: File Server IIS Sets the site. HTTP: // File: 8080, set a directory to store upload files, named UPFile. And add the current directory properties -> security -> permissions to a pre- to dedicated domain user accounts, and permissions is of course fully controlled.

On the web server, there is a UPFILE directory in the root directory. This directory is now removed from IIS, and then establishes a virtual directory in IIS, named UPFile, the target points to the UPFile directory on the file server. Of course, add-on-readable permissions.

Upload the file to the file server program: Test.cs (program running on the web server) Using system.text;

String VirtualPath = "TEST01"; // To build folder names in the UPFILE directory; string rootupfilepath = @ "http: // file: 8080 / upfile /"; // file server (server running server) String Uristring = rootupfilepath virtualpath "/"; // URL path

/RCreatedIRectory.aspx This file is used to establish a corresponding directory in the UPFILE directory on the destination server (file server). String path = rootupfilepath "createdirectory.aspx? path =" VirtualPath;

String filename = "Test.htm"; // This is the name of the file

String mystring = "This is the content of the file"; UTF8ENCODING AE = New utf8encoding ();

BYTE [] INPUT = ae.getbytes (mystring); int rtLength = INPUT.LENGTH;

String username = @ "domain_a / cqweb"; // "Domain Name / Domain User Name" String Password = @ "123456"; // domain user password

System.net.networkcredential mycred = new system.net.networkcredential (username, password); // Provide credentials for password-based authentication schemes system.net.WebClient Client = new system.net.webclient (); // Provide URI identified resources send data and public methods for receiving data from the URI identified resource system.net.credentialcache mycache = new system.net.credentialCache (); // Store credentials for Internet resources Mycache.Add (new uri (uri (uri), "Ntlm", mycred; // Add a networkcredential instance by cache to the credentials [] buffer = new byte [128];

Street.Openread (PATH); stream.read (buffer, 0, 128); // Create a directory

System.io.Stream WriteStream = Client.OpenWrite (Uristring FileName, "Put"); WriteStream.write (INPUT, 0, INTLENGTH); WRITESTREAM.CLOSE ();

Files CREATEDIRECTORY.ASPX <% @ page language = "c #"%> createDirectory </ title> <meta name = "generator" content = "Microsoft Visual Studio 7.0> < meta name = "CODE_LANGUAGE" Content = "C #"> <meta name = "vs_defaultClientScript" content = "JavaScript"> <meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5"> </ Head> <body ms_positioning = "gridLayout"> <form id = "createDirectory" method = "post" runat = "server"> <font face = "Song"> </ font> </ form> </ body> </ Html> <% string path = request.Params ["path"]. TOSTRING (). Trim (); system.io.directory.createdirectory (Server.mAppath (PATH));%></p> <p>Second, the program example example of generating an ASPX file to the file server: Idea: Transfer directly through HTTP mode, the file server is prompted to prohibit access. Because of security issues, the server is limited to file transfer of files such as ASPX, ASP. The limit is done in the .NET Framework, the relevant file is Machine.config. If you modify this file, you can solve the problem. I have consulted micro-software technical support on this issue, replying is that other security issues will be made after the revision, so it is best not to change this. It is also necessary to use the modem. Before passing, change the extension to HTML to trigger the file server-side program to change the extension to ASPX. Due to the process, file coding is mandatory to UTF-8. Chinese garbled will appear. So change the encoding to ANSI. /// <summary> /// Create a folder /// </ summary> /// <param name = "path"> Directory path, such as Upfiles / Photolib / </ param> /// <returns> returns whether successful new directory </ returns> public static bool CreateNewFolderBaseWeb (string path) {string rootUpfilePath = Com.Common.SzcmConfiguration.UploadFileWeb; // @ "http: // file: 8012 /"; string uriString = rootUpfilePath path; path = rootUpfilePath "CreateDirectory.aspx path =?" path; string username = Com.Common.SzcmConfiguration.UploadFileUser; // @ "domain_a / cqweb"; string password = Com.Common.SzcmConfiguration. UploadFilePassword; // @ "123456"; System.Net.NetworkCredential myCred = new System.Net.NetworkCredential (username, password); System.Net.WebClient Client = new System.Net.WebClient (); System.Net.CredentialCache myCache = new system.net.credentialcache (); // mycache.add (new uri (this.page.Application ["__ fspath __"]. toString ()), "ntlm", mycred; mycache.add (new URI (uri ), "Ntlm", mycred; // client.credentials = mycache; // creation directory // byte [] buffer = new byte [128]; stream stream =cl IENT.OPENREAD (PATH); //stream.read(buffer, 0, 128);</p> <p>/// <summary> /// Create a text file /// </ summary> /// <param name = "filespec"> specified by Web Directory (such as Webout / Article / 1 / 20021022093422.html) </ param> /// <param name = "content"> text file </ param> /// <returns> Return to successfully create file </ returns> public static bool createtxtFileBaseWeb (String filespec, string content) { String path; try {filespec = filespec.replace ("aspx", "html"); // First change the extension to html string virtualpath = filespec.substring (0, filespec.lastIndexof ("/"))))); String rootupfilepath = com.common.szcmconfiguration.uploadFileWeb; @ @ "http: // file: 8012 /"; string uristring = rootupfilepath virtualpath "/"; // "Upfiles /"; // put on the file server The generated HTML extension is changed to aspx path = rootupfilepath "renaMefile.aspx? Path =" filespec; system.text.utf8encoding ae = new system.text.utf8encoding (); byte [] infut = ae.getbytes (content) ; // byte [] input = System.Text.Encoding.GetEncoding ( "UTF8") GetBytes (content);. int intLength = input.Length; string username = Com.Common.SzcmConfiguration.UploadFileUser; // @ "domain_a / CQWeb "; string password = com.common. SzcmConfiguration.UploadFilePassword; // @ "123456"; System.Net.NetworkCredential myCred = new System.Net.NetworkCredential (username, password); System.Net.WebClient Client = new System.Net.WebClient ();</p> <p>System.IO.Stream writeStream = Client.OpenWrite (rootUpfilePath fileSpec, "PUT"); //System.IO.Stream writeStream = Client.OpenWrite (rootUpfilePath "upfiles / tt.txt", "PUT"); writeStream. Write (Input, 0, intlength); WriteStream.close (); stream stream = client.openread (path); // Trigger the file server side's rename. Return true;} catCH (Exception ex) {throw ex; return false;}} file renamefile.aspx <% @ page language = "c #"%> <html> <head> <title> renamefile </ title > <meta name = "GENERATOR" Content = "Microsoft Visual Studio 7.0"> <meta name = "CODE_LANGUAGE" Content = "C #"> <meta name = "vs_defaultClientScript" content = "JavaScript"> <meta name = "vs_targetSchema" Content = "http://schemas.microsoft.com/intellisense/ie5"> </ head> <body ms_positioning = "gridLayout"> <form id = "createDirectory" method = "post" runat = "server"> <font Face = "Song"> </ font> </ form> </ body> </ html> <% string path = request.params ["path"]. TOSTRING (). Trim (); System.IO.FileInfo Fi = New System.io.fileinfo (Server.mAppath (PATH));</p> <p>string content; System.IO.StreamReader oRead = fi.OpenText (); content = oRead.ReadToEnd (); oRead.Close (); System.IO.FileStream fileStream = new System.IO.FileStream (Server.MapPath (path) , System.IO.FileMode.Create); System.IO.StreamWriter streamWriter = new System.IO.StreamWriter (fileStream, System.Text.Encoding.Default); streamWriter.Write (content); streamWriter.Close (); if ( Path.indexof ("HTML")> 0) {path = path.replace ("html", "aspx"); FI.Moveto (Server.mAppath (PATH));}%> Note: At this time, if still appears Error, prompt no permissions, may be the permissions issue of the WEB server's storage temporary file. Also set up framework.c: /winnt/microsoft.net/framework/v1.0.3705/temporary ASP.NET FILES open this directory permissions to the excerime attribute in Machine.config, the username property value is the username property value of ProcessModel. "This name / aspnet"</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5597.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5597" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.034</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'F3TPt9s3ahUCCH_2F39ax4rIDQsXyBu51BNg1BQeq8SS3GsyUexPI2MUT4jDt43FBMryiLk4jDovabWZqiiz_2BRXQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>