Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

How to retrieve files at least 5 minutes old using sftp foreign

by mytutorial (Initiate)
on Nov 06, 2013 at 17:55 UTC ( #1061456=perlquestion: print w/ replies, xml ) Need Help??
mytutorial has asked for the wisdom of the Perl Monks concerning the following question:

I need to retrieve files from a directory on a remote server that are at least 5 minutes old. I am using Net::SFTP::Foreign in my Perl script. The array @directory_info contains the directory path and the filemask. I am pulling the files from the remote server using $sftp->glob. How can I only get the files that are at least 5 minutes old using $sftp->glob? The $sftp->glob portion from my script is below.

while($i < 11) { $directory = "$directory_info[$i][0]"; $filemask = "$directory_info[$i][1]"; $sftp->setcwd($directory) or $newerr=1; @list = $sftp->glob("$filemask") or $newerr=1; } $i++;

Thank you for your time and help!

Comment on How to retrieve files at least 5 minutes old using sftp foreign
Download Code
Re: How to retrieve files at least 5 minutes old using sftp foreign
by atcroft (Monsignor) on Nov 06, 2013 at 18:12 UTC

    Take a look at Net::SFTP::Foreign::Attributes (included in Net::SFTP::Foreign)-it includes methods for looking at the atime and mtime of the files. Depending on if the machines' clocks are close, then something like the following (untested) snippet might do the trick (derived from the docs):

    my $t = time; foreach my $f (@list) { if ( $f->{mtime} + 300 < $t ) { # retrieve $f->{filename} here } }

    Hope that helps.

Re: How to retrieve files at least 5 minutes old using sftp foreign
by jellisii2 (Pilgrim) on Nov 06, 2013 at 18:31 UTC
Re: How to retrieve files at least 5 minutes old using sftp foreign
by salva (Monsignor) on Nov 07, 2013 at 08:15 UTC
    my $until = time - 5 * 60; $sftp->mget($filemask, $dest, wanted => sub { $_[1]->{a}->mtime < $until });

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1061456]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-04-17 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (437 votes), past polls