in reply to Re: FTPSSL Bad file number
in thread FTPSSL Bad file number

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

Replies are listed 'Best First'.
Re^3: FTPSSL Bad file number
by Anonymous Monk on Mar 04, 2015 at 20:17 UTC

    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 }

        This is good info - it clearly shows that the elements of @files are not filenames such as B0000198800028226.xml.enc (which they should be) but rather long listings such as:

        -rwxr-xr-x    1 260        410              1571 Mar  5 08:32 B0000198800028226.xml.enc

        If you populate @files correctly in the first place then the error messages will disappear.

        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;

        What happens when $ftp->get($file) in line 156 fails?

        1. $error_flag is set in the same line
        2. $ftp->quit() is called, in line 157. Tthis will close the FTP connection.
        3. $ftp->delete() is called, in line 158. This will fail, because the FTP connection in $ftp is closed.
        4. $error_flag is set again, in line 158.
        5. $ftp->quit() is called again, in line 159. This will fail again, because the FTP connectin in $ftp is still closed.

        I don't think this is what you really want. You want to abort when $ftp->get($file) fails. Why don't you use die and eval {...} instead of fiddling with error flags? Or at least break out of the foreach loop using last?

        Anonymous Monk explained this problem in the first reply, but it seems you ignored it or did not understand it.

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)