in reply to FTPSSL Bad file number

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.

Replies are listed 'Best First'.
Re^2: FTPSSL Bad file number
by Bettan (Initiate) on Mar 04, 2015 at 20:04 UTC
    Exact error message:
    syswrite() on closed filehandle GEN0 at /usr/perl5/site_perl/5.8.4/Net +/FTPSSL.pm line 2673. Can't write command on socket: Bad file number at /usr/local/bin/debit +ech line 158 syswrite() on closed filehandle GEN0 at /usr/perl5/site_perl/5.8.4/Net +/FTPSSL.pm line 2673. Can't write command on socket: Bad file number at /usr/local/bin/debit +ech line 159 Debitech File Transfer started at Wed Mar 4 20:59:02 2015 Downloaded files: 0 Finished files: 0 Errors: 1 lwbv --------------- Retrieving file -rwxr-xr-x 1 260 410 2071 Mar + 3 10:31 B0000198800028222.xml.enc ERROR: Can't retrieve file -rwxr-xr-x 1 260 410 + 2071 Mar 3 10:31 B0000198800028222.xml.enc Bad file number

      My crystal ball is in the shop... what do lines 158 and 159 of /usr/local/bin/debitech say?

      Have you tried turning on the options "Croak", "Debug" or "Trace" of Net::FTPSSL?

        hi, this is from debug file
        >>> PASV <<< 227 Entering Passive Mode (217,151,192,136,195,210) --- Host (217.151.192.136) Port (50130) >>> RETR -rwxr-xr-x 1 260 410 1571 Mar 5 08:32 + B0000198800028226.xml.enc <<< 553 Prohibited file name: -rwxr-xr-x 1 260 410 + 1571 Mar 5 08:32 B000 0198800028226.xml.enc >>> ABOR <<< 226 Since you see this ABOR must've succeeded >>> QUIT <<< 221-Goodbye. You uploaded 0 and downloaded 0 kbytes.
        This from the prompt
        553 Prohibited file name: -rwxr-xr-x 1 260 410 +1571 Mar 5 08:32 B0000198800028226.xml.enc at /usr/local/bin/debitech line 156
        And here are the lines in my script
        151 # GET ALL FILES (*.enc) TO LOCAL DIRECTORY, DE +LETE THEM ON SERVER 152 foreach $file (@files) { 153 if ( !$error_flag && $file =~ m/\.enc$ +/ ) { 154 $report = $report . " Retriev +ing file $file\n"; 155 if ( !$debug ) { 156 $ftp->get($file) or $e +rror_flag = 1; 157 $ftp->quit() if $error +_flag; 158 $ftp->delete($file) or + $error_flag = 1; 159 $ftp->quit() if $error +_flag; 160 }