1 package Business::BatchPayment::Transport::SFTP;
3 =head2 Business::BatchPayment::Transport::SFTP
5 Import this role to use SFTP. Requires "host", "port', "user", and
6 "password" to be set. The 'sftp' method returns a Net::SFTP::Foreign
7 object providing 'get' and 'put' methods (among others). All of these
10 Also provides "get_path" and "put_path" attributes. The default 'download'
11 and 'upload' methods get and put to those paths on the SFTP host. You
12 may find it useful to modify or override that behavior.
16 use Net::SFTP::Foreign;
17 use File::Slurp qw(read_file);
19 with 'Business::BatchPayment::Transport';
21 has [ qw( host login password ) ] => (
32 has [ 'get_path', 'put_path' ] => (
39 isa => 'Net::SFTP::Foreign',
40 handles => [ 'get', 'put', 'ls', 'setcwd' ],
57 password => $self->password,
58 timeout => $self->timeout,
61 $args{'more'} = '-v' if $self->debug >= 2;
62 Net::SFTP::Foreign->new(%args);
67 die "default SFTP upload requires 'put_path'\n" unless $self->put_path;
69 my ($out, $tmpfile) = tempfile();
70 die "failed to open temporary file $tmpfile\n" unless $out;
73 $self->sftp->put($tmpfile, $self->put_path);
77 sub download { # mostly illustrative rather than directly useful
79 die "default SFTP download requires 'get_path'\n" unless $self->get_path;
80 my ($out, $tmpfile) = tempfile();
81 $self->sftp->get($self->get_path, $out);
83 return read_file($tmpfile);
86 __PACKAGE__->meta->make_immutable;