//You can add/cache credentials for a share so that you can operate them from raw IFileSystem calls
        public void StoreCredentialsForShare(NetworkCredential credential)
        {
            var domain   = credential.Domain;
            var username = credential.UserName;
            var password = credential.Password;

            var sharePath = "valid_unc/smb_sharepath"; //ie. \\host\sharename or smb://host/sharename

            _credentialProvider.AddSMBCredential(new SMBCredential(domain, username, password, sharePath, _credentialProvider));
        }
Пример #2
0
        public SMBCredential(string domain, string userName, string password, string path, ISMBCredentialProvider credentialProvider)
        {
            Domain              = domain;
            UserName            = userName;
            Password            = password;
            Path                = path;
            _credentialProvider = credentialProvider;

            Host      = path.Hostname();
            ShareName = path.ShareName();

            if (string.IsNullOrEmpty(Domain) && UserName.Contains('\\'))
            {
                var userNameParts = UserName.Split('\\');
                if (userNameParts.Length == 2)
                {
                    Domain   = userNameParts[0];
                    UserName = userNameParts[1];
                }
            }

            credentialProvider.AddSMBCredential(this);
        }