AST_CRON_audio_3_ftp.pl compare file size and --DELETE optio

Discussions about new features or changes in existing features

Moderators: gerski, enjay, williamconley, Op3r, Staydog, gardo, mflorell, MJCoate, mcargile, Kumba, Michael_N

AST_CRON_audio_3_ftp.pl compare file size and --DELETE optio

Postby okli » Sun Nov 16, 2008 11:03 pm

Hi,

I needed to check if files are successfully transferred to FTP and an option to delete from source directory if so.

Here is what I came up with, tested and worked fine so far.

The original script was modified so it compares file sizes of the transferred file with the original, and:

-if file size matches, and --DELETE is used file will be deleted from source directory
-if file size matches, and --DELETE is NOT used, file will be moved to /var/spool/asterisk/monitorDONE/FTP/ directory as normal
-if file size does NOT match, error message with file name is displayed and file are not moved nor deleted.

http://www.eflo.net/VICIDIALmantis/view.php?id=197

WARNING- if using --DELETE option please test it first, perl is not my field at all!

Hope it helps.
okli
 
Posts: 669
Joined: Mon Oct 01, 2007 5:09 pm

Postby mflorell » Mon Nov 17, 2008 5:45 pm

As long as it will not delete the file if it gets no response this should work fine. I won't have a chance to look at this until I get back to the US next week.
mflorell
Site Admin
 
Posts: 18339
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby okli » Tue Nov 18, 2008 3:48 am

It guess it would not perform any action if it gets no response, and if file sizes don't match:
Code: Select all
...
### BEGIN Remote file transfer
         $p = Net::Ping->new();
         $ping_good = $p->ping("$VARFTP_host");

         if ($ping_good)
            {
            $start_date_PATH='';
            $FTPdb=0;
            if ($DBX>0) {$FTPdb=1;}
            $ftp = Net::FTP->new("$VARFTP_host", Port => $VARFTP_port, Debug => $FTPdb);
            $ftp->login("$VARFTP_user","$VARFTP_pass");
            $ftp->cwd("$VARFTP_dir");
            if ($NODATEDIR < 1)
               {
               $ftp->mkdir("$start_date");
               $ftp->cwd("$start_date");
               $start_date_PATH = "$start_date/";
               }
            $ftp->binary();
            $ftp->put("$dir2/$ALLfile", "$ALLfile");
            usleep(1*200*1000);
            $filesize1 = -s "$dir2/$ALLfile";
            $filesize2 = $ftp->size("$ALLfile");
            if ($filesize1 = $filesize2)
               {
               if ($DB) {print " " . $ALLfile . " was successfully put to ftp" . "\r\n";}
               if (!$T)
                  {
                  if ($DEL=1)
                     {
                     `rm -f "$dir2/$ALLfile"`;
                     }
                  else
                     {
                     `mv -f "$dir2/$ALLfile" "$PATHDONEmonitor/FTP/$ALLfile"`;
                     }
                  }
               }
            else
               {
               if ($DB) {print "ERROR !!! " . $ALLfile . " was NOT successfully put to ftp" . "\r\n";}
               }
            $ftp->quit;
            $stmtA = "UPDATE recording_log set location='$VARHTTP_path/$start_date_PATH$ALLfile' where recording_id='$recording_id';";
               if($DB) {print STDERR "\n|$stmtA|\n";}
            $affected_rows = $dbhA->do($stmtA); #  or die  "Couldn't execute query:|$stmtA|\n";
            }
   ### END Remote file transfer
...


Is it possible if an error occurs while getting file sizes for local and remote file, both values to get something like 0, or -1 ?
Code: Select all
$filesize1 = -s "$dir2/$ALLfile";
$filesize2 = $ftp->size("$ALLfile");


No rush of course, whenever you get a chance. May I remind you in like 2 weeks?
okli
 
Posts: 669
Joined: Mon Oct 01, 2007 5:09 pm

Postby mflorell » Tue Nov 18, 2008 8:28 am

Yes, please do remind me in 2 weeks.

Thanks!
mflorell
Site Admin
 
Posts: 18339
Joined: Wed Jun 07, 2006 2:45 pm
Location: Florida

Postby okli » Tue Dec 02, 2008 2:40 pm

Reminding as promised :)
okli
 
Posts: 669
Joined: Mon Oct 01, 2007 5:09 pm


Return to Features

Who is online

Users browsing this forum: No registered users and 118 guests