X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FCron%2Fupload.pm;h=dceead6b302635d8b776ff6f3d67be287a38efe7;hb=781f0ffcf560d3df0aec7ae349b57463d1c2518a;hp=fea3d2cc7bb89bf4342eacd8a82d47b992230b18;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm index fea3d2cc7..dceead6b3 100644 --- a/FS/FS/Cron/upload.pm +++ b/FS/FS/Cron/upload.pm @@ -13,6 +13,7 @@ use LWP::UserAgent; use HTTP::Request; use HTTP::Request::Common; use HTTP::Response; +use Net::FTP; @ISA = qw( Exporter ); @EXPORT_OK = qw ( upload ); @@ -74,7 +75,7 @@ sub upload { eval "&billco_upload( 'agentnum' => $agentnum, 'date' => $date );"; warn "billco_upload failed: $@\n" - if ( $@ ); + if $@; } @@ -92,12 +93,13 @@ sub billco_upload { my $agentnum = $opt{agentnum} or die "no agentnum provided\n"; my $url = $conf->config( 'billco-url', $agentnum ) or die "no url for agent $agentnum\n"; + $url =~ s/^\s+//; $url =~ s/\s+$//; my $username = $conf->config( 'billco-username', $agentnum, 1 ) or die "no username for agent $agentnum\n"; my $password = $conf->config( 'billco-password', $agentnum, 1 ) or die "no password for agent $agentnum\n"; - my $clicode = $conf->config( 'billco-clicode', $agentnum ) - or die "no clicode for agent $agentnum\n"; + my $clicode = $conf->config( 'billco-clicode', $agentnum, 1 ); + #or die "no clicode for agent $agentnum\n"; die "no date provided\n" unless $opt{date}; my $zipfile = "$dir/agentnum$agentnum-$opt{date}.zip"; @@ -153,20 +155,46 @@ sub billco_upload { unlink "agentnum$agentnum-$opt{date}-header.csv", "agentnum$agentnum-$opt{date}-detail.csv"; - my $ua = new LWP::UserAgent; - my $res = $ua->request( POST( $url, - 'Content_Type' => 'form-data', - 'Content' => [ 'username' => $username, - 'pass' => $password, - 'custid' => $username, - 'clicode' => $clicode, - 'file1' => [ $zipfile ], - ], - ) - ); - - die "upload failed: ". $res->status_line. "\n" - unless $res->is_success; + if ( $url =~ /^http/i ) { + + my $ua = new LWP::UserAgent; + my $res = $ua->request( POST( $url, + 'Content_Type' => 'form-data', + 'Content' => [ 'username' => $username, + 'pass' => $password, + 'custid' => $username, + 'clicode' => $clicode, + 'file1' => [ $zipfile ], + ], + ) + ); + + die "upload failed: ". $res->status_line. "\n" + unless $res->is_success; + + } elsif ( $url =~ /^ftp:\/\/([\w\.]+)(\/.*)$/i ) { + + my($hostname, $path) = ($1, $2); + + my $ftp = new Net::FTP($hostname) #, Passive=>1 ) + or die "can't connect to $hostname: $@\n"; + $ftp->login($username, $password) + or die "can't login to $hostname: ". $ftp->message."\n"; + unless ( $ftp->cwd($path) ) { + my $msg = "can't cd $path on $hostname: ". $ftp->message. "\n"; + ( $path eq '/' ) ? warn $msg : die $msg; + } + $ftp->binary + or die "can't set binary mode on $hostname\n"; + + $ftp->put($zipfile) + or die "can't put $zipfile: ". $ftp->message. "\n"; + + $ftp->quit; + + } else { + die "unknown scheme in URL $url\n"; + } $dbh->commit or die $dbh->errstr if $oldAutoCommit; '';