diff --git a/scripts/zmfilter.pl.in b/scripts/zmfilter.pl.in index 4c3416522c..4342849584 100644 --- a/scripts/zmfilter.pl.in +++ b/scripts/zmfilter.pl.in @@ -610,6 +610,7 @@ sub uploadArchFile { } if ( $archError ) { + unlink($archLocPath); return 0; } else { if ( $Config{ZM_UPLOAD_PROTOCOL} eq 'ftp' ) { @@ -624,15 +625,30 @@ sub uploadArchFile { Error("Unable to create FTP connection: $@"); return 0; } - $ftp->login($Config{ZM_UPLOAD_USER}, $Config{ZM_UPLOAD_PASS}) - or Error("FTP - Unable to login"); - $ftp->binary() - or Error("FTP - Unable to go binary"); - $ftp->cwd($Config{ZM_UPLOAD_REM_DIR}) - or Error("FTP - Unable to cwd") - if ( $Config{ZM_UPLOAD_REM_DIR} ); - $ftp->put( $archLocPath ) - or Error("FTP - Unable to upload '$archLocPath'"); + if ( !$ftp->login($Config{ZM_UPLOAD_USER}, $Config{ZM_UPLOAD_PASS}) ) { + Error("FTP - Unable to login: ".$ftp->message); + $ftp->quit(); + unlink($archLocPath); + return 0; + } + if ( !$ftp->binary() ) { + Error("FTP - Unable to go binary: ".$ftp->message); + $ftp->quit(); + unlink($archLocPath); + return 0; + } + if ( $Config{ZM_UPLOAD_REM_DIR} and !$ftp->cwd($Config{ZM_UPLOAD_REM_DIR}) ) { + Error("FTP - Unable to cwd: ".$ftp->message); + $ftp->quit(); + unlink($archLocPath); + return 0; + } + if ( !$ftp->put( $archLocPath ) ) { + Error("FTP - Unable to upload '$archLocPath': ".$ftp->message); + $ftp->quit(); + unlink($archLocPath); + return 0; + } $ftp->quit() or Error("FTP - Unable to quit"); } else { @@ -657,11 +673,16 @@ sub uploadArchFile { Error("Unable to create SFTP connection: ".$sftp->error); return 0; } - $sftp->setcwd($Config{ZM_UPLOAD_REM_DIR}) - or Error("SFTP - Unable to setcwd: ".$sftp->error) - if $Config{ZM_UPLOAD_REM_DIR}; - $sftp->put($archLocPath, $archFile) - or Error("SFTP - Unable to upload '$archLocPath': ".$sftp->error); + if ( $Config{ZM_UPLOAD_REM_DIR} and !$sftp->setcwd($Config{ZM_UPLOAD_REM_DIR}) ) { + Error("SFTP - Unable to setcwd: ".$sftp->error); + unlink($archLocPath); + return 0; + } + if ( !$sftp->put($archLocPath, $archFile) ) { + Error("SFTP - Unable to upload '$archLocPath': ".$sftp->error); + unlink($archLocPath); + return 0; + } } unlink($archLocPath); zmDbExecute('UPDATE `Events` SET `Uploaded`=1 WHERE `Id`=?', $Event->{Id});