Getting a server local time using FTP

899 Views Asked by At

It is possible to get a local server time using FTP? I am on Smart device project in .NET and using Exceed FTP library, unfortunately these are my limitations. System.File.IO is not available to be used in Compact framework.

I first created a file on a local machine, FTPed it over to the server and copied it back.

FtpFolder destTimestampFolder = new FtpFolder(ftpConn, 
ConfigReader.AppSettings["inDir"]+"\\timestamp");

 AbstractFile localttfile = new DiskFile(ConfigReader.AppSettings["mainPath"] + ConfigReader.AppSettings["clientConfigDir"] + "\\timestamp.txt");
if (!localttfile.Exists)
{
    localttfile.Create();                    
}

localttfile.CopyTo(destTimestampFolder, true);
// copy back and grab the last accessed timestamp
AbstractFile destttfile = rootFolder.GetFile(ConfigReader.AppSettings["inDir"] + "\\timestamp\\timestamp.txt");
destttfile.CopyTo(destFolder, true);

MessageBox.Show(localttfile.LastAccessDateTime.ToString());

The timestamp displayed shows me in the local machine time. I tried showing destttfile.LastAccessDateTime and it gives me zeros.

Any workaround would be helpful. I basically would like to get a last accessed file stamp and calculate the difference.

1

There are 1 best solutions below

0
Martin Prikryl On

No, FTP protocol does not have a way to retrieve server clock.

There are two possibilities:

  1. Use MLST or MDTM commands which should return UTC timestamps of a file.
  2. Upload a new file and check its modification time.

Some (few) FTP servers allow existing some/arbitrary shell commands. You might be able to use that to retrieve the server's time.

Otherwise, you will have to use another service instead of FTP (some web service for example).