1 public class dataextractor 2 {3 static dmslogger logger = new dmslogger ("C: \ acctruesavexmltoremotelogs", "PDM "); 4 /// <summary> 5 /// Save the XML file to File Server 6 /// </Summary> 7 /// <Param name = "remotedirto"> shared directory </param> 8 /// <Param name = "remotedirto"> shared directory subdirectory </param> 9 /// <Param name = "remotedirtouser"> shared Directory Server user </param> 10 // <Param name = "remotedirtopwd"> shared directory server password </param> 11 /// <Param name = "remotedirfr Om "> local file </param> 12 // <Param name =" remotedirfromuser "> Local User </param> 13 // <Param name =" remotedirfrompwd "> Local password </param> 14 public static void savexmltofileservice (string remotedirto, string filepathto, string remotedirtouser, string delimiter, string file, string remotedirfrom, string remotedirfromuser, string remotedirfrompwd) 15 {16 try17 {18 reconnect (remotedirfrom, remotedirfromuser Rfrompwd); 19 reconnect (remotedirto, remotedirtouser, remotedirtopwd); 20 if (! Directory. exists (filepathto) 21 {22 try23 {24 directory. createdirectory (filepathto); 25 logger. writedebug ("create directory [" + filepathto + "]"); 26} 27 catch (exception ex) 28 {29 throw new exception ("[creating directory [" + filepathto + "] failed:]" + ex. message); 30} 31} 32 33 If (file. exists (File) 34 {35 logger. writedebug ("start to save the file [" + file + "] to [" + filepathto + "]"); 36 file. copy (file, filepathto + "\" + path. getfilename (file), true); 37 logger. writedebug ("save the file [" + path. getfilename (File) + "] to [" + filepathto + "] succeeded"); 38} 39 else40 {41 logger. writedebug ("file [" + file + "] does not exist"); 42} 43 // file. delete (File); 44} 45 catch (exception ex) 46 {47 logger. writeexception ("failed to save the XML file to the file server", ex); 48 throw new exception ("failed to save the XML file to the file server:" + ex. message); 49} 50} 51 52 53 public static void reconnect (string connectremotepath, string user, string PWD) 54 {55 try56 {57 if (connectremotepath. endswith ("\") 58 connectremotepath = connectremotepath. substring (0, connectremotepath. length-1); 59 system. diagnostics. PROCESS p = new system. diagnostics. process (); 60 p. startinfo. filename = "cmd.exe"; 61 p. startinfo. arguments = "/C net use \" "+ connectremotepath +" \ "/User: \" "+ User +" \ "" + PWD; 62 p. startinfo. redirectstandardoutput = true; 63 P. startinfo. redirectstandardinput = true; 64 p. startinfo. useshellexecute = false; 65 p. startinfo. createnowindow = true; 66 p. startinfo. windowstyle = system. diagnostics. processwindowstyle. hidden; 67 // P. standardinput. write (@ "net use" + connectremotepath + "/User:" + User + "" + PWD + "/persistent: yes"); 68 // P. standardinput. writeline ("exit"); 69 p. start (); 70 p. waitforexit (1000); 71 p. close (); 72 p. dispose (); 73 logger. writedebug ("server user [" + User + "] connection successful"); 74} 75 catch (exception ex) 76 {77 throw new exception ("An error occurred while accessing the shared directory: "+ ex. message); 78} 79} 80}
Cross-Server File Storage (1)