Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

How to get a ftp file date and time

by Selvakumar (Scribe)
on Aug 21, 2012 at 10:44 UTC ( [id://988688]=perlquestion: print w/replies, xml ) Need Help??

Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

i have the below code to get the list of ftp file names and i need to collect that modified time and date of that file. how i can get that? below is the code i am using and i need to have the request at the end of code where i use comment "#HERE"

use strict; use warnings; use Net::FTP; use Net::FTP::File; use File::Find::Rule; use Net::FTP::Throttle; use File::Path; use Mail::Sender; use Win32::OLE; use Cwd; our $ftp_dest; our $ftp_source; our $ftp_remove; my @ftp_folders; my @ftp_files; #To Create date on the prepress server my $hostname_prepress = 'ftp.sample.com'; my $username_prepress = 'username'; my $password_prepress = 'pass'; my $dirname_prepress = '/Folder'; my $sourcedir='/Folder/'; &collect_details($hostname_prepress, $username_prepress, $password_pre +press, $sourcedir); sub collect_details { our ($ftphost_source, $ftpuser_source, $ftppass_source, $ftpdir_sour +ce)= @_; print("\nProcess Started... FTP server connected...\n"); $ftp_source = Net::FTP::Throttle->new($ftphost_source, MegabitsPerSe +cond => 8); $ftp_source->login($ftpuser_source, $ftppass_source); $ftp_source->cwd($ftpdir_source) or die "Can't change directory ($f +tpdir_source):" . $ftp_source->message; my $pwd_source = $ftp_source->pwd; #print "$pwd_source\n"; my @ftp_details = $ftp_source->ls($pwd_source); foreach my $file (@ftp_details) { if ($ftp_source->isdir($file) eq "1") { push(@ftp_folders, "$pwd_source$file"); print "$pwd_source$file is directory\n"; } # else # { # push(@ftp_files, "$pwd_source$file"); # print "$pwd_source$file is file\n"; # } } foreach my $file (@ftp_folders) { print "$file\n"; &collect_ftp_details($file); } $ftp_source->quit; } sub collect_ftp_details { my ($path)=@_; $ftp_source->cwd($path) or die "Can't change directory ($path):" . +$ftp_source->message; my $pwd_path = $ftp_source->pwd; my @ftp_temp = $ftp_source->ls($pwd_path); print "@ftp_temp\n"; foreach my $file (@ftp_temp) { if ($ftp_source->isdir($file) eq "1") { push(@ftp_folders, "$pwd_path$file"); print "$pwd_path$file is directory\n"; } else { # push(@ftp_files, "$pwd_path$file"); #HERE print "$pwd_path$file is file\n"; } } }

Replies are listed 'Best First'.
Re: How to get a ftp file date and time
by Neighbour (Friar) on Aug 21, 2012 at 14:54 UTC
    print ("MDTM : " . $ftp_source->mdtm($file) . "\n"); Or you could read Net::FTP.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://988688]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found