Reputation: 40653
I'm using PHP's ftp_rawlist function to get a listing of files and their associated last-modified date/time. For my purposes, I need to know the time zone (or offset) of the the last-modified date/time. The dates/times alone are useless to me as I need to convert them to UTC.
Is there anyway to figure out what the FTP server's time zone setting is?
Upvotes: 10
Views: 20612
Reputation: 597941
Many (most?) FTP server's support a non-standard SITE ZONE
command for retrieving the server's timezone:
The
SITE ZONE
command requests the UTF offset for the time zone in which the server is located, allowing some FTP clients to adjust file timestamps to reflect different source/destination time zones
Though the exact format of the response differs between server implementations, so be prepared to test the response for multiple formats, or use the SYST
command to identify the server and parse accordingly.
However, this is usually not necessary anymore, as modern servers support new commands like MDTM
and MLSx
which can retrieve remote file timestamps as UTC to begin with.
Upvotes: 1
Reputation: 1
Try to define your timezone in the start of your PHP code.
Example:
date_default_timezone_set("CET");
For me this solution worked as it automatically converted the time of the server from a different timezone to the desired one.
Upvotes: -1
Reputation: 69
Well, FTP protocol doesn't provide localtime explicitly. When write access is available, you can upload new file and check modification time. With no write access, you can periodically read FTP dir and note modification time of each entry. When modification time changes, you'll know server's localtime for sure. ~30 minute check will suffice, automatic of course :)
Upvotes: 0
Reputation: 1
I recently had the same problem. My approach was to create a folder in the root called /time and then read it back and check the folders creation date. I could then establish the time difference between my ftp client and the server. Hope this helps.
BTW I am using https://github.com/ArxOne/FTP
// Establish a fallback
var servertime = DateTime.Now;
try
{
// query for the existance of a time folder
var timefolder = ftpClient.ListEntries("/").FirstOrDefault(o => o.Name == "time");
// delete it if found
if (timefolder != null)
{
ftpClient.Delete("/time");
}
// if not found create one
ftpClient.Mkd("/time");
timefolder = ftpClient.ListEntries("/").FirstOrDefault(o => o.Name == "time");
if (timefolder == null)
{
Logger.Fatal("Time check failed");
return;
}
// now grab the time of the folder.
servertime = timefolder.Date;
}
catch (Exception x)
{
Logger.Fatal(x,"Time check fatal error");
return;
}
Upvotes: 0
Reputation: 3477
There is no way defined in the FTP standard to determine remote server's time zone.
If you have write permissions to the FTP server I guess you could upload the file and then calculate the difference between the file time reported by FTP and locally.
Upvotes: 13