views:

183

answers:

3

Hi all, 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

+1  A: 

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?

tobsen
Is there any way to get round this not using samba as the version of linux installed on the box is stripped down for its application
Ross Alexander
It seems that only `GetCreationTime` method might not be supported (as underlying file systems just don't store file creation time - see `man 2 stat`). Question is about modification time, which should work.
el.pescado
You could remotely access Linux file systems using (amongst others) SMB, NFS and SSH. Only SMB is supported by Windows though, so to use NFS or SSH you'll have to hack with your Windows box, or support those protocols in your application.
el.pescado
My c# application simply needs to go over to the linux file system get the file see when it was last accessed and return this back to the application where further processing takes place
Ross Alexander
A: 

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.

Oded
I ended up creating a c++ agent to sit on the box and ftping across from the windows program thanks for your help, and support :)
Ross Alexander
A: 

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.

Eugene Mayevski 'EldoS Corp