Exemple #1
0
        public bool CopyFileByUser(string localPath, string remotePath, string fileName, string username, string password, string impersonatedUsername, string impersonatedDomain, string impersonatedPassword)
        {
            UserImpersonation impersonator = new UserImpersonation();

            bool result = impersonator.impersonateUser(impersonatedUsername, impersonatedDomain, impersonatedPassword);

            if (!result)
            {
                return(false);
            }

            string error = PinvokeWindowsNetworking.connectToRemote(remotePath, username, password);

            if (!Directory.Exists(localPath) || !Directory.Exists(remotePath))
            {
                return(false);
            }

            File.Copy(Path.Combine(localPath, fileName), Path.Combine(remotePath, fileName));

            PinvokeWindowsNetworking.disconnectRemote(remotePath);

            impersonator.undoimpersonateUser();

            return(true);
        }
Exemple #2
0
        public bool CopyFile(string localPath, string remotePath, string fileName, string username, string password)
        {
            string error = PinvokeWindowsNetworking.connectToRemote(remotePath, username, password);

            if (!Directory.Exists(localPath) || !Directory.Exists(remotePath))
            {
                return(false);
            }

            File.Copy(Path.Combine(localPath, fileName), Path.Combine(remotePath, fileName));

            PinvokeWindowsNetworking.disconnectRemote(remotePath);

            return(true);
        }
Exemple #3
0
        public IEnumerable <FileInfo> DisplayFiles(string path, string username, string password)
        {
            string error = PinvokeWindowsNetworking.connectToRemote(path, username, password);

            if (!Directory.Exists(path))
            {
                return(null);
            }

            DirectoryInfo di       = new DirectoryInfo(path);
            var           fileList = di.GetFiles()?.ToList();

            PinvokeWindowsNetworking.disconnectRemote(path);

            return(fileList);
        }