make a folder on remote machine as writable
Is there any way to make a folder on a remote machine as writable. i have the username and password of remote machine with admin pr开发者_开发百科ivileges. I want to make that folder as writable programmatically. i prefer c# to do it
You can use the DirectorySecurity class to change the folder access privileges:
// Create a new DirectoryInfo object corresponding to the remote folder.
DirectoryInfo dirInfo = new DirectoryInfo("remoteDirectoryPath");
// Get a DirectorySecurity object that represents the current security settings.
DirectorySecurity dirSecurity = dirInfo.GetAccessControl();
string user = "domain\\userForWhichTheRightsAreChanged";
// add the write rule for the remote directory
dirSecurity.AddAccessRule(new FileSystemAccessRule(user, FileSystemRights.Write, AccessControlType.Allow));
// Set the new access settings.
dirInfo.SetAccessControl(dirSecurity);
If your code does not run under the account that has administrative privileges on the remote machine, please also consider using impersonation. A complete sample about how to impersonate a user is available here.
精彩评论