0

我正在编写一个 perl 脚本,它可以使用 FTP 逐步将本地目录与远程目录同步。它检查每个文件的最后修改日期并将其与一个远程文件的比较。我使用以下代码通过 FTP 获取上次修改时间。

 my $f = Net::FTP->new($config->{'host'}, Passive => 1, Debug => 0) || die "Couldn't ftp to $config->{'host'}: $@";
 $f->mdtm($file);

如果本地机器和远程机器具有相同的时间和时区,它会很好用,如果不是,我需要解决方法!

提前致谢

4

2 回答 2

1

据我所知,不存在仅使用 ftp 命令知道为 FTP 服务器设置的时区的方法……无论如何,如果您有写权限,您可以尝试在远程 FTP 服务器上创建一个文件,然后执行“ls” 可以查看日期/时间戳,具有新创建文件的时间戳,您可以计算本地时区和服务器时区之间的差异

$f->touch('test.time') or die $f->message; #Creates new zero byte file
$f->mdtm('test.time'); #Now you should have the local time of the FTP Server
#Now you can compare with your local time and find the difference ...

touch在尝试使用命令创建测试文件之前,请确保该测试文件不存在。

于 2013-09-22T08:11:48.047 回答
1

从 (stat file[9]) 获得的修改时间不取决于配置的时区服务器吗?

我几乎同时在具有不同时区的两台服务器中触摸了一个示例文件。获得的修改时间非常相似。只有最后 4 位数字不同。

Server 1
--------
root@- [~/ftp_kasi]# touch file
root@- [~/ftp_kasi]# perl mdtime.pl 
1380005862
root@- [~/ftp_kasi]# date
Tue Sep 24 02:59:19 EDT 2013
root@- [~/ftp_kasi]#

Server 2
--------
root@ffVM32 kasi]# touch file
[root@ffVM32 kasi]# perl mdtime.pl 
1380006066
[root@ffVM32 kasi]# date
Tue Sep 24 12:38:45 IST 2013
[root@ffVM32 kasi]# 

 [root@ffVM32 kasi]# cat mdtime.pl 
#!/usr/local/cpanel/3rdparty/bin/perl

$file = "file";
#open my $fh,'<',$file or  die "Could not open file : $!\n";
#my $mdtime = (stat($fh))[9];

open (FILE, "file");
my $mdtime = (stat(FILE))[9];

print $mdtime."\n";
于 2013-09-24T07:10:39.543 回答