Please provide exact error messages, as you don't tell us which line of your example code the error happens (How do I post a question effectively?). I can only make a guess:

$ftp->get($file) or $error_flag = 1; $ftp->quit if $error_flag; $ftp->delete($file) or $error_flag = 1; $ftp->quit if $error_flag;

This logic says that if $ftp->get($file) returns a false value, to call $ftp->quit, and then call $ftp->delete($file), even though by then the connection might be closed. Also, although apparently not related to your error message:

opendir( DIR, "$debug_ftp_directory/$directory_local" ) or $error_flag = 1; @files = readdir(DIR); closedir(DIR);

That's not quite right as it will attempt to readdir and closedir even if the opendir fails. It's usually better to opendir ... or die ... and handle the error elsewhere.

In general, you seem to be relying quite heavily on $error_flag to control the flow of your program, which leads to lots of repeated statements (if ( !$error_flag ... and $ftp->quit) and logic that can easily break if you later insert more statements into the code. I would suggest you look into flow control statements like last and next, as well as breaking your code down into subroutines from which you can return. Even dieing or croaking combined with Try::Tiny (or similar) is a good method for exception handling - for example, you could place your error counting/reporting into a catch block, $ftp->quit into a finally block, and then just die from the main code in the try block in case of errors.


In reply to Re: FTPSSL Bad file number by Anonymous Monk
in thread FTPSSL Bad file number by Bettan

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.