/// <summary>Execute commands.</param> /// <param name="desktop">Object type Desktop.</param> /// <author>Luis Domingo Rueda Wilches - [email protected].</author> /// <date>11/23/2019</date> public void ExecuteCommands(Desktop desktop) { string[] dirs; string remotePath = @"\\" + desktop.Name + @"\vivelab"; TxCopied.Text += "\r\n"; using (UNCAccess unc = new UNCAccess()) { if (unc.NetUseWithCredentials(remotePath, Username, "", Password)) { dirs = Directory.GetDirectories(remotePath); foreach (string d in dirs) { Directory.Delete(d, true); } LocalPaths.ForEach((local) => { string destination = (remotePath + @"\" + Path.GetFileName(local.Path)); CopyFiles(local.Path, destination, true); TxCopied.Text += destination + "\r\n"; }); } else { this.Cursor = Cursors.Default; string msn = remotePath + "\r\nCódigo Error: = " + unc.LastError.ToString(); TxErrors.Text += msn + "\r\n\n"; } } }
private void ConnectToUNC(BasePathsDb baseDb) { //Path is \\<server>@<username>:<password>\rest\of\the\path // Regex x = new Regex(@"\\\\(?<server>.*?)@(?<user>.*?):(?<pass>.*?)\\(?<path>.*?)$", RegexOptions.IgnoreCase); // MatchCollection mc = x.Matches(aBasePath.sBasePath); // // if (mc.Count != 0) // { // string sServer = mc[0].Groups["server"].Value; // string sUser = mc[0].Groups["user"].Value; // string sPassword = mc[0].Groups["pass"].Value; // string sPath = mc[0].Groups["path"].Value; // aBasePath.sBasePath = @"\\" + sServer + @"\" + sPath; //Create a UNC connector UNCAccess pUNC = new UNCAccess(); //to be added in array based on ID //Fire up a task to connect var bgw = new BackgroundWorker(); bgw.DoWork += (_, __) => { if (!pUNC.login(baseDb.BasePath, baseDb.Username, "", baseDb.Password)) { Console.WriteLine("Could not connect to: " + baseDb.BasePath); } }; bgw.RunWorkerCompleted += (_, __) => { Console.WriteLine("Finished connecting to UNC: " + baseDb.BasePath); }; bgw.RunWorkerAsync(); //Add the entry to the list of UNCs BasePathsUNC sUNC = new BasePathsUNC { pUNC = pUNC, Id = baseDb.Id }; aUNCConnections.Add(sUNC); }