Solved

Change file permission on a Unix file using C# / .NET

Posted on 2003-12-04
4
1,234 Views
Last Modified: 2007-12-19
I am in the process of converting an existing Windows Perl program to C# using Visual Studio .NET.

This is a Windows Application and it will create a text file on a shared UNIX file server. By default it creates the file with RWE permission only to user that invokes the appplication. How can I change the file permission on the file using C# or the .NET framework? That is perform what would be equivalent to "chmod 777" to the UNIX file.

I was able to perform the above in Perl but haven't been able to figure out how to do it on C#.

Thanks.
0
Comment
Question by:khrispy
  • 3
4 Comments
 
LVL 6

Expert Comment

by:martinv
ID: 9900401
How are you doing it in perl (considering the application runs on the Windows box)? With rsh or rexec? Try to do it the same in c#.
0
 

Author Comment

by:khrispy
ID: 9900761
In Perl I used the Win32 Perl extentions to set the file protection as follows:

   $mask = Win32::FileSecurity::MakeMask("FULL");

  %permissions = ('Everyone' => $mask,                                         $group => $mask,
                  $user => $mask);

   Win32::FileSecurity::Set($filepath, \%permissions);


  note "FULL" is equivalent to 'RWE' permission

The above funtion to set file protection was meant for Windows NTFS files but they seemd to work also on the UNIX files

The UNIX system where the files are being created is SAMBA-enabled on our network so the Windows client systems on the same network sees it just as another drive.

Maybe you can show me how to use C#/.Net to set the protection on Windows files (RWE for specified group and/or  'everyone') and maybe the same method will work for the UNIX files.

Thanks
0
 
LVL 6

Accepted Solution

by:
martinv earned 500 total points
ID: 9901002
Hi,
samba-enabled unix server drive is for .NET programs almost the same as normal Windows NTFS drive, so standard windows methods should work.

Please try .NET managed c++ library found here
http://www.codeproject.com/dotnet/NTSecurityNET.asp

It can be also done with System.Management classes.
For more info read following thread:
http://www.dotnet247.com/247reference/msgs/14/73727.aspx
0
 
LVL 6

Expert Comment

by:martinv
ID: 9901172
BTW - another (but probably not optimal) option is uploading the file to the unix server via FTP component which is capable of calling chmod command for setting file permissions directly on the unix server.  I know one, but it's not free.

See http://web.rebex.net/ftp.net/samples.aspx

I think, that there is also some free ones - maybe try to look at www.codeproject.com.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now