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_user", 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 $newerr==3; print ("Deleting file $file ...... Success!\n"); } $newerr = "0"; }