FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old September 14th, 2003, 09:27 PM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old September 14th, 2003, 10:04 PM
breadwild breadwild is offline
*foo = *bar;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Wheaton, IL
Posts: 161 breadwild User rank is Sergeant (500 - 2000 Reputation Level)breadwild User rank is Sergeant (500 - 2000 Reputation Level)breadwild User rank is Sergeant (500 - 2000 Reputation Level)breadwild User rank is Sergeant (500 - 2000 Reputation Level)breadwild User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 7 h 59 m 53 sec
Reputation Power: 20
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();
    }
}

Reply With Quote
  #3  
Old September 14th, 2003, 10:37 PM
meonkeys meonkeys is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Seattle, WA
Posts: 4 meonkeys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to meonkeys
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.

Reply With Quote
  #4  
Old September 14th, 2003, 11:47 PM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
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.

Reply With Quote
  #5  
Old September 15th, 2003, 12:15 AM
meonkeys meonkeys is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Seattle, WA
Posts: 4 meonkeys User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to meonkeys
Quote:
well the output given is
"Modification Time: 1062987059"


This is a unix timestamp. Try this:
Code:
use strict;
use Date::Format;
print time2str("%C", 1062987059);


Good luck!
-Adam

Reply With Quote
  #6  
Old September 15th, 2003, 03:41 AM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
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

Reply With Quote
  #7  
Old September 15th, 2003, 09:20 PM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
need HELP on the above message... i still cant figure out...

HELP?

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > Time and Date of File when FTP?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway