如何获取:FTP 服务器的时区设置?

发布于 2024-09-09 05:40:01 字数 150 浏览 4 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甜嗑 2024-09-16 05:40:01

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.

南风几经秋 2024-09-16 05:40:01

许多(大多数?)FTP 服务器支持非标准 SITE ZONE 命令来检索服务器的时区:

SITE ZONE 命令请求服务器所在时区的 UTF 偏移量,允许某些 FTP 客户端调整文件时间戳以反映不同的源/目标时区

尽管响应的确切格式有所不同在服务器实现之间,因此准备测试多种格式的响应,或使用 SYST 命令来识别服务器并进行相应的解析。

然而,这通常不再是必要的,因为现代服务器支持像 MDTM 和 MLSx 这样的新命令,它们可以检索远程文件时间戳作为 UTC 开始。

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.

睡美人的小仙女 2024-09-16 05:40:01

我最近也遇到了同样的问题。我的方法是在根目录中创建一个名为 /time 的文件夹,然后读回并检查文件夹创建日期。然后我可以确定 ftp 客户端和服务器之间的时差。希望这有帮助。

顺便说一句,我正在使用 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;
}

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;
}
把时间冻结 2024-09-16 05:40:01

嗯,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 :)

断爱 2024-09-16 05:40:01

尝试在 PHP 代码的开头定义您的时区。

示例:

date_default_timezone_set("CET");

对于我来说,这个解决方案有效,因为它自动将服务器的时间从不同的时区转换为所需的时区。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文