From f8d1263de9cec1ae5b69e9b265ba39d5ed57d82e Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 22 Apr 2011 23:30:22 +0000 Subject: [PATCH] wtxs upload changes, RT#12326 --- FS/FS/Cron/upload.pm | 53 ++++++++++++++++++++++++++++++++++++++-------------- bin/billco-upload | 2 +- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/FS/FS/Cron/upload.pm b/FS/FS/Cron/upload.pm index fea3d2cc7..cb6c62876 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 ); @@ -153,20 +154,44 @@ 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) + or die "can't connect to $hostname: $@\n"; + $ftp->login($username, $password) + or die "can't login to $hostname: ". $ftp->message."\n"; + $ftp->cwd($path) + or die "can't cd $path on $hostname: ". $ftp->message. "\n"; + $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; ''; diff --git a/bin/billco-upload b/bin/billco-upload index 4efc18005..a84750ab2 100644 --- a/bin/billco-upload +++ b/bin/billco-upload @@ -6,7 +6,7 @@ use FS::Cron::upload; adminsuidsetup shift or die "usage: billco-upload username agentnum\n"; my $agentnum = shift or die "usage: billco-upload username agentnum\n"; -FS::Cron::upload::billco_upload( 'agentnum' => $agentnum +FS::Cron::upload::billco_upload( 'agentnum' => $agentnum, 'v' => 1, 'l' => 2, ); -- 2.11.0