Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I have a script that is supposed to pull a few files from a remote server daily. I am having a problem with the the file names since they have the timestamp at the end. I want to be able to use wildcards for the last part of each file and the first characters are known. This is what I have now. This only trys to get a file called 0 and 1. I can't find a way to match "IRP_*" to find a file called "IRP_0304041213"

use Net::SFTP::Foreign; use Switch; use Net::SFTP::Foreign::Constants qw(:error); my $leap_year = 0; my $inter_server = "0.0.0.0"; my $ai_user = "guest"; my $ai_pass = "password"; #Want to encrypt these in script my $ai_dir = ""; my $ai_dest_day = "/APP/FTP/Daily/Input"; my $ai_dest_mon = "/APP/FTP/Monthly/Input"; my @ai_files_day = qw{IRP_ trigextract_ VRP_}; my @ai_files_mon = qw{snapshot_ }; my ($sec, $min, $hour, $day, $month, $year) = localtime; my $sftp = Net::SFTP::Foreign->new($inter_server, user => "$ai_use +r", password => "$ai_pass"); # Add 'more => '-v'' debug $sftp->error and warn "SFTP connection failed: " . $sftp->error; print ("Connected to $inter_server($inter_server)\n"); print "Trying to login to $inter_server \n"; print ("Login was successful.\n"); foreach my $file (@ai_files_day){ #daily list our $newerr = "0"; $file .= "$yesterday"; #$mfile .= "mod_yester"; $file = $sftp->glob("${file}*"); print ("$file\n"); #This is for debug. $sftp->mget("$ai_dir/${file}", "$ai_dest_day/${file}") or $newerr= +1; print "Failed to retreive file $file : $!\n" if $newerr==1; next if $newerr; print ("Retreiving file $file ...... Success!\n"); if ($newerr != 1){ $sftp->remove("$ai_dir/${file}*")or $newerr=3; print "Deleting file $file ...... Failed!: $!\n" if $newer +r==3; print ("Deleting file $file ...... Success!\n"); } $newerr = "0"; }

Any suggestions for something to try to make this work?


In reply to Net::SFTP::Foreign getting files by kofs79

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found