开发者

Accessing linux file system in a C# program

开发者 https://www.devze.com 2023-01-09 14:23 出处:网络
I am programming a C# application that checks the last time a file was modified on 3 different servers, one of these being linux. Being a different file system what are the possible ways to check when

I am programming a C# application that checks the last time a file was modified on 3 different servers, one of these being linux. Being a different file system what are the possible ways to check when said file was last modified on the system.

I have full access to modifying the server to an extent but I am looking for a number of 开发者_高级运维creative solutions to get round this problem.

Thanks in advance


You can use the System.IO.File classes static methods to get information you need:

    DateTime written = File.GetLastWriteTime(fileName);
    DateTime accessed = File.GetLastAccessTime(fileName);
    DateTime created = File.GetCreationTime(fileName); 

This should work for files shared by your linux server via samba too. Also you can run this .Net code with mono on the linux machine - but it seems that not all linux filesystems support all of the above methods properly.

Update:

You could use a ftp and poll that instead of a network share. To access the date time filed you can send a ftp-webrequest with WebRequestMethods.Ftp.GetDateTimestamp to the server.

But maybe I've got your requirements wrong: do you need to check files from one machine on 3 machines? Or should those 3 machines check their files independently from each other? Are the results meant to be gathered by one "service"? Or are the results only relevant to the one machine the file belongs to?


The easiest thing, if your application is going to run on a windows box is to run and configure SAMBA on the linux box and use it to expose the linux folders a network shares using SMB.

This will allow you to access the linux folder the same way you would access any other windows network share.

Other options are to use NFS on the linux box and use an NFS client (see this SO question), or try mono directly on the linux box.


For linux the most obvious solution is SFTP. Most linux distributions have SSH/SFTP server built-in and running by default. Now, SFTP protocol provides a standard listing format for directories so that you can get the listing and read file times there.

0

精彩评论

暂无评论...
验证码 换一张
取 消