Renci.SshNet.Sftp.SftpFileAttributes.SetPermissions C# (CSharp) Method

SetPermissions() public method

Sets the permissions.
public SetPermissions ( short mode ) : void
mode short The mode.
return void
        public void SetPermissions(short mode)
        {
            if (mode < 0 || mode > 999)
            {
                throw new ArgumentOutOfRangeException("mode");
            }

            var modeBytes = mode.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0').ToCharArray();

            var permission = (modeBytes[0] & 0x0F) * 8 * 8 + (modeBytes[1] & 0x0F) * 8 + (modeBytes[2] & 0x0F);

            OwnerCanRead = (permission & S_IRUSR) == S_IRUSR;
            OwnerCanWrite = (permission & S_IWUSR) == S_IWUSR;
            OwnerCanExecute = (permission & S_IXUSR) == S_IXUSR;

            GroupCanRead = (permission & S_IRGRP) == S_IRGRP;
            GroupCanWrite = (permission & S_IWGRP) == S_IWGRP;
            GroupCanExecute = (permission & S_IXGRP) == S_IXGRP;

            OthersCanRead = (permission & S_IROTH) == S_IROTH;
            OthersCanWrite = (permission & S_IWOTH) == S_IWOTH;
            OthersCanExecute = (permission & S_IXOTH) == S_IXOTH;
        }

Usage Example

Example #1
0
 public void SetPermissionsTest()
 {
     SftpFileAttributes target = new SftpFileAttributes(); // TODO: Initialize to an appropriate value
     short mode = 0; // TODO: Initialize to an appropriate value
     target.SetPermissions(mode);
     Assert.Inconclusive("A method that does not return a value cannot be verified.");
 }