in reply to ftp'ing 'Find' results from an array
my $ftpSession; if (login($current, getPass($current))) { @dirs = retrDirs(); @goodFiles = retrFiles(); foreach (@goodFiles) { {Insert code here} } if (@dirs) { foreach (@dirs) { _recparseTree ($_,""); } } } #This begins a new ftp session with a passed username and password sub login { my ($user, $pass) = @_; $ftpSession = Net::FTP->new($server, Debug => 0) or die printError +Entry ("", "Error logging into server."); $ftpSession->login($user,$pass) or return 0; $ftpSession->cwd("{base dir}"); return 1; } #This simply gets the current directory. sub getStruct { return $ftpSession->ls(); } #This reads the current directory, and picks out all .html, .htm, .htm +lx, and .pdf files, and returns an array sub retrFiles { my @tempfiles = getStruct(); my @results; foreach (@tempfiles) { if ($_ =~ m{\.HTM} || $_ =~ m{\.PDF} ) { push(@results,$_); } } return @results; } #This reads the current directory, and picks out all subdirectories, r +eturning an array of results sub retrDirs { my @tempdirs = getStruct(); my @results; foreach (@tempdirs) { if ($_ =~ m{\.DIR} ) { push(@results,substr($_,0, index($_,"."))); } } return @results; } sub _recparseTree { #get directory name my ($dir, $dirname) = @_; $dirname.= "\/".$dir; #Change directory to target $ftpSession->cwd("[.$dir]"); #Get the structure my @tempList = retrFiles(); my @tempDirs = retrDirs(); #If there are files in the directory. if (@tempList) { {Insert code here} foreach (@tempList){ {Insert code here} } } if (@tempDirs) { foreach (@tempDirs) { _recparseTree($_, $dirname) +; } } $ftpSession->cwd(".."); }
|
|---|