X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=FS%2Fbin%2Ffreeside-cdr-sftp_and_import;h=aa1b3942c99ff68f2f84c75126e56227e69b48ba;hb=0191f49853fc8f1ff7c8a608600474bc23ffa69d;hp=9aacd67533ed25fa9e62db1aea8f9d99653e2017;hpb=bd86f39993db7511cb71a66c11ed56f5fa48be28;p=freeside.git diff --git a/FS/bin/freeside-cdr-sftp_and_import b/FS/bin/freeside-cdr-sftp_and_import index 9aacd6753..aa1b3942c 100755 --- a/FS/bin/freeside-cdr-sftp_and_import +++ b/FS/bin/freeside-cdr-sftp_and_import @@ -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_g $opt_s $opt_b ); +getopts('c:m:p:r:e:d:v:P:agsb'); $opt_e ||= 'csv'; #$opt_e = ".$opt_e" unless $opt_e =~ /^\./; @@ -116,31 +116,39 @@ foreach my $filename ( @$ls ) { $import_options->{'cdrtypenum'} = $opt_c if $opt_c; my $error = FS::cdr::batch_import($import_options); + if ( $error ) { - unlink "$cachedir/$filename"; - unlink "$cachedir/$ungziped" if $opt_g; - die $error; - } - if ( $opt_d ) { - if($opt_m eq 'ftp') { - my $ftp = ftp(); - $ftp->rename($filename, "$opt_d/$file_timestamp") - or do { - unlink "$cachedir/$filename"; - unlink "$cachedir/$ungziped" if $opt_g; - die "Can't move $filename to $opt_d: ".$ftp->message . "\n"; - }; + if ( $opt_s ) { + warn "$ungziped: $error\n"; + } else { + unlink "$cachedir/$filename"; + unlink "$cachedir/$ungziped" if $opt_g; + die $error; } - else { - my $sftp = sftp(); - $sftp->rename($filename, "$opt_d/$file_timestamp") - or do { - unlink "$cachedir/$filename"; - unlink "$cachedir/$ungziped" if $opt_g; - die "can't move $filename to $opt_d: ". $sftp->error . "\n"; - }; + + } else { + + if ( $opt_d ) { + if ( $opt_m eq 'ftp') { + my $ftp = ftp(); + $ftp->rename($filename, "$opt_d/$file_timestamp") + or do { + unlink "$cachedir/$filename"; + unlink "$cachedir/$ungziped" if $opt_g; + die "Can't move $filename to $opt_d: ".$ftp->message . "\n"; + }; + } else { + my $sftp = sftp(); + $sftp->rename($filename, "$opt_d/$file_timestamp") + or do { + unlink "$cachedir/$filename"; + unlink "$cachedir/$ungziped" if $opt_g; + die "can't move $filename to $opt_d: ". $sftp->error . "\n"; + }; + } } + } unlink "$cachedir/$filename"; @@ -168,6 +176,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; } @@ -213,6 +222,8 @@ 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