default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / FS / bin / freeside-cdr-sftp_and_import
index 722bf73..f2bf294 100755 (executable)
@@ -12,8 +12,8 @@ use FS::cdr;
 # parse command line
 ###
 
-use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v $opt_P $opt_a $opt_c $opt_g $opt_s );
-getopts('c:m:p:r:e:d:v:P:ags');
+use vars qw( $opt_m $opt_p $opt_r $opt_e $opt_d $opt_v $opt_P $opt_a $opt_c $opt_i $opt_g $opt_s $opt_b );
+getopts('c:i:m:p:r:e:d:v:P:agsb');
 
 $opt_e ||= 'csv';
 #$opt_e = ".$opt_e" unless $opt_e =~ /^\./;
@@ -21,7 +21,8 @@ $opt_e =~ s/^\.//;
 
 $opt_p ||= '';
 
-die "invalid cdrtypenum" if $opt_c && $opt_c !~ /^\d+$/;
+die "invalid cdrtypenum" if defined $opt_c && $opt_c !~ /^\d+$/;
+die "invalid carrierid"  if defined $opt_i && $opt_i !~ /^\d+$/;
 
 my %options = ();
 
@@ -113,14 +114,15 @@ foreach my $filename ( @$ls ) {
     'batch_namevalue' => $file_timestamp,
     'empty_ok'        => 1,
   };
-  $import_options->{'cdrtypenum'} = $opt_c if $opt_c;
+  $import_options->{'cdrtypenum'} = $opt_c if defined $opt_c;
+  $import_options->{'carrierid'}  = $opt_i if defined $opt_i;
   
   my $error = FS::cdr::batch_import($import_options);
 
   if ( $error ) {
 
     if ( $opt_s ) {
-      warn "$ungzipped: $error\n";
+      warn "$ungziped: $error\n";
     } else {
       unlink "$cachedir/$filename";
       unlink "$cachedir/$ungziped" if $opt_g;
@@ -161,7 +163,11 @@ foreach my $filename ( @$ls ) {
 ###
 
 sub usage {
-  "Usage: \n  cdr.import user format servername\n";
+  "Usage:
+  freeside-cdr-sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ]
+    [ -r remotefolder ] [ -d donefolder ] [ -v level ] [ -P port ]
+    [ -a ] [ -g ] [ -s ] [ -c cdrtypenum ] user format [sftpuser@]servername
+  ";
 }
 
 use vars qw( $sftp $ftp );
@@ -176,6 +182,7 @@ sub ftp {
     or die "FTP connection to '$hostname' failed.";
   $ftp->login($ftp_user, $ftp_pass) or die "FTP login failed: ".$ftp->message;
   $ftp->cwd($opt_r) or die "can't chdir to $opt_r\n" if $opt_r;
+  $ftp->binary or die "can't set BINARY mode: ". $ftp->message if $opt_b;
   return $ftp;
 }
 
@@ -198,9 +205,10 @@ freeside-cdr-sftp_and_import - Download CDR files from a remote server via SFTP
 
 =head1 SYNOPSIS
 
-  cdr.sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ] 
+  freeside-cdr-sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ] 
     [ -r remotefolder ] [ -d donefolder ] [ -v level ] [ -P port ]
-    [ -a ] [ -g ] [ -s ] [ -c cdrtypenum ] user format [sftpuser@]servername
+    [ -a ] [ -g ] [ -s ] [ -c cdrtypenum ] [ -i carrierid]
+    user format [sftpuser@]servername
 
 =head1 DESCRIPTION
 
@@ -221,11 +229,15 @@ or FTP and then import them into the database.
 
 -a: use ftp passive mode
 
+-b: use ftp binary mode
+
 -v: set verbosity level; this script only has one level, but it will 
     be passed as the 'debug' argument to the transport method
 
 -c: cdrtypenum to set, defaults to none
 
+-i: carrierid to set, defaults to none
+
 -g: File is gzipped
 
 -s: Warn and skip files which could not be imported rather than abort