I'm using the Filesys::SmbClientParser module to retrieve files from a file share. The module is working pretty good, but every now and then my script does not pick up one of the files from the share. The output says that it did pick up the file, but it does not actually pick it up. Here is my code:

# 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 retriev +e remote directory listing: ".$smb->err." - Going to next transfer.") +; next; } # parse through the remote directory listing, looking for files th +at we want foreach (@remote_list){ # if no files were specified to get... if ($remote_file eq ''){ &logEntry($args{'logfile'}, "$jobname-ERROR: No files spec +ified to get. Exiting"); exit; # if the file we are looking for is just a filename with no wi +ldcards... } elsif ($remote_file !~ /\*/){ # if the file is not a dir and it matches our pattern, pus +h 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 ont +o the array # if $remote_file_pattern is empty, it means that "*" was +asked for if($_->{attr} ne "D" && ($_->{name} =~ /$remote_file_patte +rn/ || $remote_file_pattern eq '')){ push(@files_to_get, $_->{name}); } } } if (@files_to_get == 0){ &logEntry($args{'logfile'}, "$jobname-RUNNING: There are no re +mote 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 g +et $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 the +m if($delete_remote_files ne "NO"){ &logEntry($args{'logfile'}, "$jobname-RUNNING: Att +empting 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_d +ir"."$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."); } } }

Does anyone have any idea why I'm getting sporadic file pickup failures? This code consistently spits out a "1", showing a success even if the file was not retrieved:

$smb->get ("$file")

Thanks! Vic


In reply to Filesys::SmbClientParser Get Files Randomly Fails with no Error by csftpteam

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.