如何获取:FTP 服务器的时区设置?
我使用 PHP 的 ftp_rawlist 函数来获取文件列表及其关联的上次修改日期/时间。出于我的目的,我需要知道最后修改的日期/时间的时区(或偏移量)。仅日期/时间对我来说毫无用处,因为我需要将它们转换为 UTC。
有没有办法弄清楚 FTP 服务器的时区设置是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
FTP 标准中没有定义确定远程服务器时区的方法。
如果您对 FTP 服务器有写权限,我想您可以上传文件,然后计算 FTP 报告的文件时间与本地报告的文件时间之间的差异。
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.
许多(大多数?)FTP 服务器支持非标准
SITE ZONE
命令来检索服务器的时区:尽管响应的确切格式有所不同在服务器实现之间,因此准备测试多种格式的响应,或使用 SYST 命令来识别服务器并进行相应的解析。
然而,这通常不再是必要的,因为现代服务器支持像 MDTM 和 MLSx 这样的新命令,它们可以检索远程文件时间戳作为 UTC 开始。
Many (most?) FTP server's support a non-standard
SITE ZONE
command for retrieving the server's timezone: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
andMLSx
which can retrieve remote file timestamps as UTC to begin with.我最近也遇到了同样的问题。我的方法是在根目录中创建一个名为 /time 的文件夹,然后读回并检查文件夹创建日期。然后我可以确定 ftp 客户端和服务器之间的时差。希望这有帮助。
顺便说一句,我正在使用 https://github.com/ArxOne/FTP
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
嗯,FTP 协议没有明确提供本地时间。当写访问可用时,您可以上传新文件并检查修改时间。如果没有写访问权限,您可以定期读取 FTP 目录并记下每个条目的修改时间。当修改时间改变时,您肯定会知道服务器的当地时间。 〜30 分钟检查就足够了,当然是自动的:)
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 :)
尝试在 PHP 代码的开头定义您的时区。
示例:
对于我来说,这个解决方案有效,因为它自动将服务器的时间从不同的时区转换为所需的时区。
Try to define your timezone in the start of your PHP code.
Example:
For me this solution worked as it automatically converted the time of the server from a different timezone to the desired one.