in reply to Error Checking with Net::FTP

If I'm not mistaken, the second check is redundant. You're successfully doing $ftp-put($sub_log), and then trying to do it a second time with the line if($ftp->put($sub_log)) {, which fails because it's trying to put a file that already exists. Try the last block as:
$ftp->put($sub_log) or ErrorOut("FTP Put Failed ", $ftp->message); $ftp->quit; print "\nEnd FTP debug output\n\n"; print "FTP Put successful from server $ftp_server\n";
If there's a problem, ErrorOut() should be able to report/handle it.

Replies are listed 'Best First'.
Re^2: Error Checking with Net::FTP
by nickfaber (Initiate) on Jan 07, 2008 at 19:30 UTC
    Thanks for the quick replies! Actually the FTP is working fine. What I need is a way to determine after the get/put if it was sucessful. A sample of my output may clear it up:
    FTP Debug output: Net::FTP=GLOB(0x4041cfd8)<<< 220 server FTP server ready. Net::FTP=GLOB(0x4041cfd8)>>> USER weblogs Net::FTP=GLOB(0x4041cfd8)<<< 331 Password required for weblogs. Net::FTP=GLOB(0x4041cfd8)>>> PASS .... Net::FTP=GLOB(0x4041cfd8)<<< 230 User weblogs logged in. Net::FTP=GLOB(0x4041cfd8)>>> CWD /export/home/weblogs/subsidiary/ Net::FTP=GLOB(0x4041cfd8)<<< 250 CWD command successful. Net::FTP=GLOB(0x4041cfd8)>>> PORT 170,6,240,108,208,249 Net::FTP=GLOB(0x4041cfd8)<<< 200 PORT command successful. Net::FTP=GLOB(0x4041cfd8)>>> RETR subsidiary.28067.access.file.log Net::FTP=GLOB(0x4041cfd8)<<< 150 Opening ASCII mode data connection fo +r subsidiary.28067.access.file.log (40641 bytes). Net::FTP=GLOB(0x4041cfd8)<<< 226 Transfer complete. Net::FTP=GLOB(0x4041cfd8)>>> QUIT Net::FTP=GLOB(0x4041cfd8)<<< 221-You have transferred 40841 bytes in 1 + files. Net::FTP=GLOB(0x4041cfd8)<<< 221-Total traffic for this session was 41 +290 bytes in 1 transfers. Net::FTP=GLOB(0x4041cfd8)<<< 221-Thank you for using the FTP service o +n server. Net::FTP=GLOB(0x4041cfd8)<<< 221 Goodbye. End FTP debug output FTP Get Failed
    See the FTP debug shows the get was sucessful, yet my logic to determine this is flawed.
    if ($ftp->put($sub_log)) { print "FTP Put successful from server $ftp_server\n"; }else{ print "FTP Put Failed\n"; }
      You are already checking that the put/get succeeds in the original call:
      $ftp->put($sub_log) or ErrorOut("put failed ", $ftp->message);
      That will call ErrorOut if the put fails.
      You then $ftp->quit to close the connection, and call $ftp->put after that in the if statement, which will try uploading the file again (fails because the connection is closed).
      In that case, maybe capture the result of your put command and check against that:
      my $success = $ftp->put($sub_log); if ($success) { print "FTP Put successful from server $ftp_server\n"; } else { # handle and report errors }

      FTP Get Failed

      Huh? Where did that come from ... there's no get in the code you posted.

      -derby
      BTW...ErrorOut is a simple subroutine I use to write error contents to a log file and delete a program lockfile if it exists.
      sub ErrorOut { ################################################################## +######################## # # This subroutine write all STDERR to the log file and deletes th +e Lock File. # ################################################################## +######################## my $error = shift; print "$error\n"; # # Delete the Lock File # if (-e $lock_file) { if (unlink($lock_file) == 1) { print "Lock File $lock_file deleted successfully.\n\n"; } else { print "Lock File $lock_file could not be deleted.\nEnsure +the UID running this program has proper permissions\n"; # exit 1; } } # exit 1; } # End sub ErrorOut