my $pattern = '\\Aaudit'; my $no_file_error ="TRUE"; my @dir_files = $ftp->dir($ftp_directory); $Data::Dumper::Useqq=1; print Dumper($pattern); my $netrc = Net::Netrc->lookup($ftp_server) or die ("Could not find login info in .netrc for $ftp_server"); my $ftp = Net::FTP->new($ftp_server, Port => $ftp_server_port, Debug => 1) or die ('Could not create ftp object'); $ftp->login($netrc->login, $netrc->password) or die ('Could not log in'), $ftp->message; $ftp->binary(); #print directory of files before command print "--------------------First List all files------------------\n"; my @dir_files = $ftp->dir($ftp_directory); foreach my $list(@dir_files){ print "$list\n"; } @dir_files = grep { $_ =~ /$pattern/ } @dir_files; if (@dir_files == 0) { if ($no_file_error eq "TRUE") { print "No files exist with that $pattern\n"; } else { print "Send Email: Cannot find files to GET for parameter $pattern"; }} else { for my $list(@dir_files){ print "$ftp_command $list\n"; } } #### $VAR1 = "audit"; Net::FTP>>> Net::FTP(2.77) Net::FTP>>> Exporter(5.63) Net::FTP>>> Net::Cmd(2.29) Net::FTP>>> IO::Socket::INET(1.31) Net::FTP>>> IO::Socket(1.31) Net::FTP>>> IO::Handle(1.28) Net::FTP=GLOB(0xaec9e8)<<< 220 Titan FTP Server 11.20.2264 Ready. Net::FTP=GLOB(0xaec9e8)>>> USER xupromgr Net::FTP=GLOB(0xaec9e8)<<< 331 User name okay, need password. Net::FTP=GLOB(0xaec9e8)>>> PASS .... Net::FTP=GLOB(0xaec9e8)<<< 230-Welcome xupromgr from 10.253.2.119. You are now logged in to the server. Net::FTP=GLOB(0xaec9e8)<<< 230 User logged in, proceed. Net::FTP=GLOB(0xaec9e8)>>> TYPE I Net::FTP=GLOB(0xaec9e8)<<< 200 Type set to I. --------------------First List all files------------------ Net::FTP=GLOB(0xaec9e8)>>> PASV Net::FTP=GLOB(0xaec9e8)<<< 227 Entering Passive Mode (10,253,1,56,236,13). Net::FTP=GLOB(0xaec9e8)>>> LIST /AS/testftp Net::FTP=GLOB(0xaec9e8)<<< 150 File status okay; about to open data connection. Net::FTP=GLOB(0xaec9e8)<<< 226 Closing data connection. Transferred 415 bytes. drw-rw---- 1 xupromgr xupromgr 512 Mar 29 08:04 . drw-rw---- 1 xupromgr xupromgr 512 Mar 28 13:54 .. -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit.txt -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit_date.txt -rw-rw---- 1 xupromgr xupromgr 10 Feb 27 14:08 auditsample.txt -rw-rw---- 1 xupromgr xupromgr 11 Feb 27 14:21 audit_date.txt get -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit.txt get -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit_date.txt get -rw-rw---- 1 xupromgr xupromgr 10 Feb 27 14:08 auditsample.txt get -rw-rw---- 1 xupromgr xupromgr 11 Feb 27 14:21 audit_date.txt #### $VAR1 = "^audit"; Net::FTP>>> Net::FTP(2.77) Net::FTP>>> Exporter(5.63) Net::FTP>>> Net::Cmd(2.29) Net::FTP>>> IO::Socket::INET(1.31) Net::FTP>>> IO::Socket(1.31) Net::FTP>>> IO::Handle(1.28) Net::FTP=GLOB(0x1cdf9e8)<<< 220 Titan FTP Server 11.20.2264 Ready. Net::FTP=GLOB(0x1cdf9e8)>>> USER xupromgr Net::FTP=GLOB(0x1cdf9e8)<<< 331 User name okay, need password. Net::FTP=GLOB(0x1cdf9e8)>>> PASS .... Net::FTP=GLOB(0x1cdf9e8)<<< 230-Welcome xupromgr from 10.253.2.119. You are now logged in to the server. Net::FTP=GLOB(0x1cdf9e8)<<< 230 User logged in, proceed. Net::FTP=GLOB(0x1cdf9e8)>>> TYPE I Net::FTP=GLOB(0x1cdf9e8)<<< 200 Type set to I. --------------------First List all files------------------ Net::FTP=GLOB(0x1cdf9e8)>>> PASV Net::FTP=GLOB(0x1cdf9e8)<<< 227 Entering Passive Mode (10,253,1,56,235,244). Net::FTP=GLOB(0x1cdf9e8)>>> LIST /AS/testftp Net::FTP=GLOB(0x1cdf9e8)<<< 150 File status okay; about to open data connection. Net::FTP=GLOB(0x1cdf9e8)<<< 226 Closing data connection. Transferred 415 bytes. drw-rw---- 1 xupromgr xupromgr 512 Mar 29 08:04 . drw-rw---- 1 xupromgr xupromgr 512 Mar 28 13:54 .. -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit.txt -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit_date.txt -rw-rw---- 1 xupromgr xupromgr 10 Feb 27 14:08 auditsample.txt -rw-rw---- 1 xupromgr xupromgr 11 Feb 27 14:21 audit_date.txt No files exist with that ^audit #### $VAR1 = "\\Aaudit"; Net::FTP>>> Net::FTP(2.77) Net::FTP>>> Exporter(5.63) Net::FTP>>> Net::Cmd(2.29) Net::FTP>>> IO::Socket::INET(1.31) Net::FTP>>> IO::Socket(1.31) Net::FTP>>> IO::Handle(1.28) Net::FTP=GLOB(0x18539e8)<<< 220 Titan FTP Server 11.20.2264 Ready. Net::FTP=GLOB(0x18539e8)>>> USER xupromgr Net::FTP=GLOB(0x18539e8)<<< 331 User name okay, need password. Net::FTP=GLOB(0x18539e8)>>> PASS .... Net::FTP=GLOB(0x18539e8)<<< 230-Welcome xupromgr from 10.253.2.119. You are now logged in to the server. Net::FTP=GLOB(0x18539e8)<<< 230 User logged in, proceed. Net::FTP=GLOB(0x18539e8)>>> TYPE I Net::FTP=GLOB(0x18539e8)<<< 200 Type set to I. --------------------First List all files------------------ Net::FTP=GLOB(0x18539e8)>>> PASV Net::FTP=GLOB(0x18539e8)<<< 227 Entering Passive Mode (10,253,1,56,236,32). Net::FTP=GLOB(0x18539e8)>>> LIST /AS/testftp Net::FTP=GLOB(0x18539e8)<<< 150 File status okay; about to open data connection. Net::FTP=GLOB(0x18539e8)<<< 226 Closing data connection. Transferred 415 bytes. drw-rw---- 1 xupromgr xupromgr 512 Mar 29 08:04 . drw-rw---- 1 xupromgr xupromgr 512 Mar 28 13:54 .. -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit.txt -rw-rw---- 1 xupromgr xupromgr 18 Feb 27 14:21 no_audit_date.txt -rw-rw---- 1 xupromgr xupromgr 10 Feb 27 14:08 auditsample.txt -rw-rw---- 1 xupromgr xupromgr 11 Feb 27 14:21 audit_date.txt No files exist with that \Aaudit