# 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 );
-getopts('c:m:p:r:e:d:v:P:ag');
+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 =~ /^\./;
$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";
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;
}
cdr.sftp_and_import [ -m method ] [ -p prefix ] [ -e extension ]
[ -r remotefolder ] [ -d donefolder ] [ -v level ] [ -P port ]
- [ -a ] [ -c cdrtypenum ] user format [sftpuser@]servername
+ [ -a ] [ -g ] [ -s ] [ -c cdrtypenum ] user format [sftpuser@]servername
=head1 DESCRIPTION
-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
+-g: File is gzipped
+
+-s: Warn and skip files which could not be imported rather than abort
+
user: freeside username
format: CDR format name