use OpenILS::Utils::Cronscript;
use OpenILS::Utils::Fieldmapper;
use OpenSRF::Utils::Logger qw/$logger/;
-binmode(STDOUT, ":utf8");
my %defaults = (
- 'osrf-config=s' => '/openils/conf/opensrf_core.xml',
- 'response-file=s' => '',
- 'verbose' => 0
+ 'osrf-config=s' => '/openils/conf/opensrf_core.xml',
+ 'response-file=s' => '',
+ 'remote-account=s' => 0,
+ 'remote-file=s' => '',
+ 'local-file=s' => '', # store fetched file locally
+ 'verbose' => 0
);
sub help {
$o->bootstrap;
my $file = $opts->{'response-file'};
+my $remote_account = $opts->{'remote-account'};
+my $remote_file = $opts->{'remote-file'};
+my $local_file = $opts->{'local-file'};
+my $verbose = $opts->{'verbose'};
+
+die "--response-file OR --remote-account and --remote-file required\n"
+ unless $file or ($remote_account and $remote_file);
+
+if (!$file and $remote_account) {
+
+ my $racct = $o->editor->retrieve_config_remote_account($remote_account);
+ die "No such remote account $remote_account" unless $racct;
+
+ my $type;
+ my $host = $racct->host;
+ ($host =~ s/^(S?FTP)://i and $type = uc($1)) or
+ ($host =~ s/^(SSH|SCP)://i and $type = 'SCP');
+
+ if ($local_file) {
+ $file = $local_file;
+ } else {
+ my $tmp_file = File::Temp->new();
+ $file = $tmp_file->filename;
+ }
+
+ my $acct = OpenILS::Utils::RemoteAccount->new(
+ type => $type,
+ account_object => $racct,
+ local_file => $file,
+ remote_file => $remote_file
+ );
+
+ my $res = $acct->put;
+
+ die "Unable to push to remote server [$remote_account] : " .
+ $acct->error . "\n" unless $res;
+
+ print "Pushed file to $res\n" if $verbose;
+}
+
+# at this point, $file contains CSV, because it was already there or
+# because we just fetched it from the remote account
open(FILE, $file) or
die "Unable to open response file: '$file' : $!\n";
+
+binmode(FILE, ":utf8");
my $e = $o->editor(connect => 1);