# if the transfer is a GET } elsif ($cmd eq "GET") { my @remote_list; my @files_to_get; # get the remote directory listing so we can parse through it @remote_list = $smb->dir; # if @remote_list = 1, it means that the share is inaccessible if(@remote_list == 1){ &logEntry($args{'logfile'}, "$jobname-ERROR: Could not retrieve remote directory listing: ".$smb->err." - Going to next transfer."); next; } # parse through the remote directory listing, looking for files that we want foreach (@remote_list){ # if no files were specified to get... if ($remote_file eq ''){ &logEntry($args{'logfile'}, "$jobname-ERROR: No files specified to get. Exiting"); exit; # if the file we are looking for is just a filename with no wildcards... } elsif ($remote_file !~ /\*/){ # if the file is not a dir and it matches our pattern, push it onto the array if($_->{attr} ne "D" && $_->{name} eq $remote_file){ push(@files_to_get, $_->{name}); } # if the file we are looking for is wildcarded... } elsif ($remote_file =~ /\*/){ my $remote_file_pattern = $remote_file; $remote_file_pattern =~ s/\*//; $remote_file_pattern =~ s/\./\\./; # if the remote file name matches our pattern, push it onto the array # if $remote_file_pattern is empty, it means that "*" was asked for if($_->{attr} ne "D" && ($_->{name} =~ /$remote_file_pattern/ || $remote_file_pattern eq '')){ push(@files_to_get, $_->{name}); } } } if (@files_to_get == 0){ &logEntry($args{'logfile'}, "$jobname-RUNNING: There are no remote files to get matching $remote. Going to next transfer."); next; } # loop through for each file in the glob foreach (@files_to_get) { my $file = $_; # THIS DOES NOT WORK - FILES BEING COPIED INTO THE REMOTE DIR DO NOT SHOW UP AS SUCH # check that the size of remote file is not still changing my $dir_size = 0; my $dir_tmp_size = -1; #while ( $dir_size ne $dir_tmp_size ) { # $dir_tmp_size = $dir_size; # $dir_size = $smb->du; # get the remote directory size # sleep(5); # print "DIR_SIZE:$dir_size;\n"; #} &logEntry($args{'logfile'}, "$jobname-RUNNING: Attempting to get $remote_dir".$file." to $local_dir"); my $i = 0; # try to get the file 4 times while($i < 4){ # get the remote file if ($smb->get ("$file")){ &logEntry($args{'logfile'}, "$jobname-SUCCESS: $remote_dir"."$file retrieved successfully"); $smb_out = $smb->get ("$file"); &logEntry($args{'logfile'}, "$jobname-DEBUG: $smb_out"); # if config is not set to not delete files; delete them if($delete_remote_files ne "NO"){ &logEntry($args{'logfile'}, "$jobname-RUNNING: Attempting to delete $remote_dir".$file); # delete the remote file if ($smb->del ("$file")) { &logEntry($args{'logfile'}, "$jobname-SUCCESS: $remote_dir"."$file deleted successfully"); } else{ &logEntry($args{'logfile'}, "$jobname-ERROR: $remote_dir"."$file might not have been deleted successfully: ".$smb->err); } } $i = 5; } else { &logEntry($args{'logfile'}, "$jobname-ERROR: $remote_dir"."$file might not have been retrieved successfully: ".$smb->err." - Trying again in 1 minute."); sleep (1); $i += 1; } if($i == 4){ &logEntry($args{'logfile'}, "$jobname-ERROR: Transfer failed for the fourth time. Going to the next transfer."); } } }