|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Time and Date of File when FTP?
ok... manually, during ftp... when i enter ll... it will show the date and time of the files listed. how am i going to get the time and date of each file generated by the machine in a program that use Net::FTP?
The program i did able to for loop and get each file using Net::FTP but i do not know how to get the time and date of the files. how will i go about this? this are the sub function which i did to for loop each file and get the file with a .txt extension but i do not know how to get the time and date of the file. Code:
sub netftp{
use net::FTP;
$ftp=Net::FTP->new("202.12.45.45", Debug =>0) or die "Cannot connect";
$ftp->message;
$home = "/speg/diyar/PERLTOOLS/TEST";
ftp->cwd($home);
@dircontents= $ftp->ls;
$ftp-> quit;
my $wildcard=".txt";
for each (@dircontents)
{
if($_=~$wildcard){
print"Wildcard:$_";
}else{print "no such file\n";}
}
}
the above codes for my subroutine able to print all the files but not the date and time... and i also wish to get the date and time to do some conditions such as if the date is from June to september then get file. or for reference purposes. THank-You -PerloWacko-19yrs of age
__________________
U go PERL.. perlomatic |
|
#2
|
|||
|
|||
|
Code:
# NOTE: This following format will return the date that the
# file was created in the form:
# "Day, Mon DayOfMonth Hour:Minute:Second Year"
# $created = fileage('date', $foo)
#
## NOTE: This following format will return the date that the
# file was last modified in the form:
# "Day, Mon DayOfMonth Hour:Minute:Second Year"
# $modified = fileage('mod', $foo)
#
sub fileage {
my($type, $fl, $constant, %fa, @fa_keys, $fa_a,
$fa_found, $fa_temp1, $fa_temp2, $integer_off);
$type = $_[0];
$fl = $_[1];
$integer_off = $_[2];
if(-e "$fl") {
$constant = (-C "$fl");
%fa = (); $fa_found = 0;
$fa{'sec'} = $constant * 86400;
$fa{'min'} = $constant * 1440;
$fa{'hr'} = $constant * 24;
$fa{'day'} = $constant;
$fa{'wk'} = $constant / 7;
$fa{'yr'} = $constant / 365;
$fa_temp1 = $^T - int((-M "$fl") * 86400);
$fa_temp2 = $^T - int((-C "$fl") * 86400);
$fa{'mod'} = localtime($fa_temp1);
$fa{'date'} = localtime($fa_temp2);
if($type) {
unless($type =~ /\D[^\.]/) {
if($integer_off) {
$fa{'p'} = $constant / $type;
} else {
$fa{'p'} = int($constant / $type);
}
}
}
@fa_keys = keys(%fa);
unless($integer_off) {
for($fa_a = 0; $fa_a <= $#fa_keys; $fa_a++) {
unless($fa_keys[$fa_a] =~ /date|mod|p/) {
$fa{$fa_keys[$fa_a]} = int($fa{$fa_keys[$fa_a]});
}
}
$fa_a = 0;
}
if($type) {
for($fa_a = 0; $fa_a <= $#fa_keys; $fa_a++) {
if($type eq $fa_keys[$fa_a]) {
return($fa{$fa_keys[$fa_a]});
$fa_found = 1;
last;
}
}
unless($fa_found) {
return($fa{'p'});
}
} else {
return($fa{'sec'}, $fa{'min'}, $fa{'hr'},
$fa{'day'}, $fa{'wk'}, $fa{'yr'}, $fa{'date'}, $fa{'mod'});
}
# undef($type, $fl, $constant, %fa, @fa_keys, $fa_a, $fa_found, $fa_temp1, $fa_temp2, $integer_off);
} else {
return();
}
}
|
|
#3
|
|||
|
|||
|
You will not be able to reliably obtain the date of files on an FTP server. If possible, have the creator of the files include the date as part of the filename.
|
|
#4
|
|||
|
|||
|
ermmm.... well i did read the Net:: FTP module documentation and found out i can get the time using mdtm which give out the modification time of the file... but i cant figure out what the output means... maybe its rubbish or hexadecimal.... but still i cant interprete it.... this is the code i did in the foreach loop and had move the "$ftp->quit;" at the end of the file...
Code:
foreach(@dircontents){
@mod_time=$ftp->mdtm($_);
print "Modification Time: @mod_time";
}
well the output given is "Modification Time: 1062987059" i cant interprete the numbers above.... is it rubbish or hexadecimal? the real time of the file is 34 sep 8 03:10. Tanks. |
|
#5
|
|||
|
|||
|
Quote:
This is a unix timestamp. Try this: Code:
use strict;
use Date::Format;
print time2str("%C", 1062987059);
Good luck! -Adam |
|
#6
|
|||
|
|||
|
alrite... im downloading the CPAN module for use Date::Format . tanks =D cant wait to try it out
but does anyone know how to check whetjer there's a valid directory if there isnt then it will make new directory.... i want to copy files to target directory but if there's no such thing as target directory then it will make dat directory and copy the file into it. get it? well these is the codes i come out with but never werk Code:
my $target_directory="/home/speg/cyril/diyar";
foreach(@dircontents){
#if there no such directory then it make that directory and copy the file into it... if there already have that directory then it just copy the file into it.
if($target_directory==0){
mkdir $target_directory, 0777;
copy $file $target_directory;
}else{copy $file $target_directory;}
}
thanks-Diyar |
|
#7
|
|||
|
|||
|
need HELP on the above message... i still cant figure out...
HELP? |
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > Time and Date of File when FTP? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|