Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Net::SFTP::Foreign getting files

by salva (Abbot)
on Apr 11, 2013 at 14:14 UTC ( #1028164=note: print w/replies, xml ) Need Help??


in reply to Re^2: Net::SFTP::Foreign getting files
in thread Net::SFTP::Foreign getting files

Oh, I see, you are calling glob in scalar context where it returns the number of files matching. Also, you don't need mget when you have already used glob to resolve the name. get will do in that case:
($file) = $sftp->glob($file, names_only => 1); defined $file or die "file not found"; $sftp->get($file, "$ai_dest_day/$file");

Replies are listed 'Best First'.
Re^4: Net::SFTP::Foreign getting files
by kofs79 (Initiate) on Apr 11, 2013 at 14:47 UTC

    Ok now I am getting the file names and downloading them the way I was hoping for with one exception. In my script I want a file "IRP_20130410" the remote server has a file named "IRP_20130410000438.txt" The remote windows machine adds 6 characters for time and the ".txt" extension. I want to be able to match the file name I am looking for and don't care about the remaining characters. So can I just put a wild card in the glob?

    ($file) = $sftp->glob("${file}*", names_only => 1); defined $file or die "file not found"; $sftp->get($file, "$ai_dest_day/$file");
      yes, glob also accepts Perl regular expressions:
      ... my $start = quotemeta "$file$yesterday"; my ($file) = $sftp->glob(qr/^$start\d{6}$/, names_only => 1); ...
      But there are easier ways to do what you want. For instance, you can use a regular expression matching all the prefixes in @ai_files_day plus $yesterday plus any six digits and let mget download all the files matching:
      $sftp->setcwd($ai_dir); my $starts = join('|', map quotemeta, @ai_files_day); $sftp->mget(qr/^(?:$starts)$yesterday\d{6}$/, $ai_dest_day);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1028164]
help
Chatterbox?
[Corion]: Meh. I get the feeling I should post a call-to-action for people to test their modules with the upcoming 5.26 (or 5.25.latest), as it seems that the smoke testers don't really weed out modules that fail without . in @INC
[Corion]: But without instructions on how to easily test things yourself, I don't think such a call to arms is helpful
[Corion]: (this post on nntp.perl.org / p5p makes it seem to me that smoke testers seem to have a blind spot there)
[Corion]: Hmmm. Maybe setting $ENV{PERL5LIB}=" some path without dot"; perl Makefile.PL; make test already is enough to locally test your module...
[Corion]: Meh, no, will need a BEGIN hook...
[Corion]: ... and PERL5OPT does not like -e in it :-(

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-03-27 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (317 votes). Check out past polls.