Reputation: 2589
I am writing a perl script that can sync a local directory with remote directory incremently using FTP. It checks last modified date of each file and compare it with one remote file's. I use the following code to get last modified time via FTP.
my $f = Net::FTP->new($config->{'host'}, Passive => 1, Debug => 0) || die "Couldn't ftp to $config->{'host'}: $@";
$f->mdtm($file);
It works great if local machine and remote machine have same time and timezone, I need to get a workaround if they are not!
Thanks in advance
Upvotes: 0
Views: 2158
Reputation: 2589
Does modification time obtained from (stat file[9]) not depend upon which timezone server configured with?
I touched a sample file almost simultaneously in two servers with different timzones. Modification time obtained was very similar. only last 4 digits were dissimilar.
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";
Upvotes: 1
Reputation: 72636
As far as I know it doesn't exist a way to know the timezone set for an FTP Server using only ftp commands ... Anyway, if you have write permission you could try creating a file on the remote FTP Server and then doing an "ls" on it to see the date/time stamp, having the timestamp of the newly created file you could calculate the difference between your local timezone and the server time zone.
$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 ...
Make sure that the test file doesn't exist before trying create one with touch
command .
Upvotes: 1