protected bool TransferDirectoryContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args) { if (!args.Overwrite) { ValidateSourceAndDestinationContents(src, dst, args); } if (args.DoRecursiveCopy) { RecursiveCopy(src, dst, args); } var srcContents = src.ListFilesInDirectory(src.IOPath); var result = true; var origDstPath = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(dst.IOPath.Path); if (!dst.PathExist(dst.IOPath)) { CreateDirectory(dst, args); } // TODO: cleanup this code so that result is easier to follow foreach (var p in srcContents) { result = PerformTransfer(src, dst, args, origDstPath, p, result); } Dev2Logger.Debug($"Transfered: {src.IOPath.Path}", GlobalConstants.WarewolfDebug); return(result); }
/// <summary> /// Transfer the contents of the directory /// </summary> /// <param name="src"></param> /// <param name="dst"></param> /// <param name="args"></param> bool TransferDirectoryContents(IActivityIOOperationsEndPoint src, IActivityIOOperationsEndPoint dst, IDev2CRUDOperationTO args) { ValidateSourceAndDestinationContents(src, dst, args); if (args.DoRecursiveCopy) { RecursiveCopy(src, dst, args); } var srcContents = src.ListFilesInDirectory(src.IOPath); var result = true; var origDstPath = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(dst.IOPath.Path); if (!dst.PathExist(dst.IOPath)) { CreateDirectory(dst, args); } foreach (var p in srcContents) { result = PerformTransfer(src, dst, args, origDstPath, p, result); } Dev2Logger.Debug($"Transfered: {src.IOPath.Path}"); return(result); }
private IList <IActivityIOPath> ListDirectoriesAccordingToType(IActivityIOPath src, ReadTypes type) { IList <IActivityIOPath> result = new List <IActivityIOPath>(); string path = src.Path; if (!path.EndsWith("\\") && PathIs(src) == enPathType.Directory) { path += "\\"; } if (!RequiresAuth(src)) { try { IEnumerable <string> dirs; if (!Dev2ActivityIOPathUtils.IsStarWildCard(path)) { if (Directory.Exists(path)) { dirs = GetDirectoriesForType(path, string.Empty, type); } else { throw new Exception(string.Format(ErrorResource.DirectoryDoesNotExist, path)); } } else { // we have a wild-char path ;) string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path); string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path); dirs = GetDirectoriesForType(baseDir, pattern, type); } if (dirs != null) { foreach (string d in dirs) { result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, true, src.PrivateKeyFile)); } } } catch (Exception) { throw new Exception(string.Format(ErrorResource.DirectoryNotFound, src.Path)); } } else { try { // handle UNC path SafeTokenHandle safeTokenHandle; bool loginOk = LogonUser(ExtractUserName(src), ExtractDomain(src), src.Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, out safeTokenHandle); if (loginOk) { using (safeTokenHandle) { WindowsIdentity newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle()); using (WindowsImpersonationContext impersonatedUser = newID.Impersonate()) { // Do the operation here try { IEnumerable <string> dirs; if (!Dev2ActivityIOPathUtils.IsStarWildCard(path)) { dirs = GetDirectoriesForType(path, string.Empty, type); } else { // we have a wild-char path ;) string baseDir = Dev2ActivityIOPathUtils.ExtractFullDirectoryPath(path); string pattern = Dev2ActivityIOPathUtils.ExtractFileName(path); dirs = GetDirectoriesForType(baseDir, pattern, type); } if (dirs != null) { foreach (string d in dirs) { result.Add(ActivityIOFactory.CreatePathFromString(d, src.Username, src.Password, src.PrivateKeyFile)); } } } catch (Exception) { throw new Exception(string.Format(ErrorResource.DirectoryNotFound, src.Path)); } // remove impersonation now impersonatedUser.Undo(); newID.Dispose(); } } } else { // login failed throw new Exception(string.Format(ErrorResource.FailedToAuthenticateUser, src.Username, src.Path)); } } catch (Exception ex) { Dev2Logger.Error(ex); throw; } } return(result); }