Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

Trying to FTP files based on Last Modified date

My plan is to review files in a particular folder. I'd run the program in a cron job  any of them shows a Last Modified date of the current day, I want to FTP all the files.
I though this would be a start…nothing.
This is obviously only the part of determing if the files need to be FTPd

I'd appreciate any help, and any hints on doing the rest of what I want to do.

Thanks
###########################################

/usr/bin/perl

use CGI qw/:all/;

$path="proj/psl/www/namer/parts/calendar/html";                      
{
   (opendir DOCS,"$path")                        
}
      @files=sort grep !/^\.\.?$/,  readdir DOCS;

    closedir DOCS;

    chop($date = `date +" %m/%d/%y "`);

    foreach  (@files) {
   
             $filename = $_;
          ($name,$ext)=split /\./,$filename;
          ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=stat "$path/$filename";
          ($sec,$min,$hour,$mday,$mon,$myear) = localtime($mtime);
          $mmonth = $mon+1;
          $xyear=$myear+1900;

print  "$name, $mtime \n";
               
             }
0
tmccar10
Asked:
tmccar10
  • 4
  • 3
1 Solution
 
Perl_DiverCommented:
this should get you the files in the folder less than a day old sorted newest to oldest:

my $path="proj/psl/www/namer/parts/calendar/html";
opendir(DOCS,"$path") or die "$!";                        
my @files = sort {$b <=> $a} grep {-M "$path/$_" < 1}  readdir DOCS;
close(DOCS);
print "$_ ", scalar localtime((stat("$path/$_"))[9]), "\n" for @files;
0
 
Perl_DiverCommented:
You then use a module like Net::FTP (a core module) to ftp the files in @files where you want them to go.  I think the documentation for the module might be enough for you to know how to use it but ask more questions if need be:

http://perldoc.perl.org/Net/FTP.html
0
 
tmccar10Author Commented:
Thanks-

I've come down with a virus (the medical kind) and I'm running out of gas..

I test this ASAP.

Thanks again
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tmccar10Author Commented:
Thanks-

This is much more efficient then FTPing all the files.
I've never use Net::FTP and I went to the perldoc.

A couple of questions, if I may:

How do I tell the program to get files in @files?

I've ftp'd before, and there are commands(methods) I don't see in the module:
-mget/mput-for multiple files
-cd or lcd to change local and remote directories

Thanks again
0
 
Perl_DiverCommented:
to change dirs on the local machine you use perls chdir() function.To change dirs on the ftp site you use the NET::FTP function:

cwd ( [ DIR ] )

as explained in the documentation:

<quote>
cwd ( [ DIR ] )
    Attempt to change directory to the directory given in $dir. If $dir is "..", the FTP CDUP command is used to attempt to move up one directory. If no directory is given then an attempt is made to change the directory to the root directory.

cdup ()
    Change directory to the parent of the current directory.

pwd ()
    Returns the full pathname of the current directory.
<unquote>

How do I tell the program to get files in @files?

here is an example you can buld on:

use Net::FTP;

my $path="proj/psl/www/namer/parts/calendar/html";
opendir(DOCS,"$path") or die "$!";                        
my @files = sort {$b <=> $a} grep {-M "$path/$_" < 1}  readdir DOCS;
close(DOCS);

my $ftp = Net::FTP->new("some.host.name", Debug => 0);
$ftp->login("name","password");
$ftp->cwd("/pub");
foreach my $files (@files) {
   $ftp->put("$path/$files");
}
$ftp->quit;

0
 
tmccar10Author Commented:
Thanks Perl Diver-

I don't have everything actually running, but what you've given me will get me there.

I appreciate the help and the extra boost on Net::FTP. The stuff I do is very simple, just meant to get me "from here to there" and the old ways had been working 'til recently. OR I'm just stubborn.

Thansk again.
0
 
Perl_DiverCommented:
You're welcome, thanks for the points. :)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now