kofs79 has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SFTP::Foreign getting files
by salva (Canon) on Apr 11, 2013 at 13:35 UTC | |
by kofs79 (Initiate) on Apr 11, 2013 at 14:01 UTC | |
by salva (Canon) on Apr 11, 2013 at 14:14 UTC | |
by kofs79 (Initiate) on Apr 11, 2013 at 14:47 UTC | |
by salva (Canon) on Apr 11, 2013 at 15:14 UTC |