Net-OpenSSH-Compat
view release on metacpan or search on metacpan
lib/Net/OpenSSH/Compat/SSH2.pm view on Meta::CPAN
$ssh->scp_get($remote, $local);
if ($ssh->error) {
$cpt->_set_error(LIBSSH2_ERROR_SCP_PROTOCOL => "scp_get failed");
return
}
1
}
sub scp_put {
my ($cpt, $local, $remote) = @_;
$cpt->_check_state('ok');
unless (defined $remote) {
$remote = File::Basename::basename($local);
}
my $ssh = $cpt->{ssh};
$ssh->scp_put($local, $remote);
if ($ssh->error) {
$cpt->_set_error(LIBSSH2_ERROR_SCP_PROTOCOL => "scp_get failed");
return
}
1
}
sub channel {
my $cpt = shift;
$cpt->_check_state('ok');
my $class = join('::', ref($cpt), 'Channel');
my $chan = $class->_new($cpt);
push @{$cpt->{channels}}, $chan;
$cpt->_free_channels;
$chan;
}
sub sftp {
my $cpt = shift;
$cpt->_check_state('ok');
my $class = join('::', ref($cpt), 'SFTP');
$class->_new($cpt);
}
package Net::OpenSSH::Compat::SSH2::Channel;
our @ISA = qw(IO::Handle Net::OpenSSH::Compat::SSH2::Base);
sub _new {
my ($class, $cpt) = @_;
my $chan = $class->SUPER::new;
*$chan = { cpt => $cpt,
state => 'new',
error => [0, "", ""],
blocking => 1 };
return $chan;
}
sub _hash { *{shift @_}{HASH} }
sub _parent { shift->_hash->{cpt} }
sub ext_data { $_[0]->_hash->{ext_data} = $_[1] }
sub setenv {
my $ch = shift->_hash;
my $env = $ch->{env} ||= {};
%$env = (%$env, @_);
1;
}
sub _exec {
my $chan = shift;
$chan->_check_state('new') or return;
my $defs = $DEFAULTS{channel};
my %opts = ( ($defs ? @$defs : ()),
(ref $_[0] ? %{shift @_} : ()),
stdinout_socket => 1 );
my $ch = $chan->_hash;
my $mode = $ch->{ext_data};
my $cpt = $ch->{cpt};
my $ssh = $cpt->{ssh};
$mode ||= 'normal';
if ($mode eq 'ignore') {
$opts{stderr_discard} = 1;
}
elsif ($mode eq 'merge') {
$opts{stderr_to_stdout} = 1;
}
else {
$opts{stderr_pipe} = 1;
}
local %ENV = (%ENV, %{$ch->{env}}) if $ch->{env};
my ($io, undef, $err, $pid) = $ssh->open_ex(\%opts, @_);
if ($ssh->error) {
$chan->_set_error(LIBSSH2_ERROR_SOCKET_DISCONNECT => $ssh->error);
$ch->{state} = 'failed';
return
}
$chan->fdopen($io, 'r+');
$chan->autoflush(1);
binmode $chan;
$ch->{err} = $err;
$ch->{pid} = $pid;
$ch->{state} = 'exec';
$chan->_blocking($ch->{cpt}{blocking});
return 1;
}
sub exec { shift->_exec(@_) }
sub shell { shift->_exec }
sub subsystem { shift->_exec({ssh_opts => ['-s']}, @_) }
sub send_eof {
my $chan = shift;
shutdown $chan, 1
}
sub close {
my $chan = shift;
$chan->_check_state('exec') or return;
my $ch = $chan->_hash;
$chan->SUPER::close;
( run in 0.833 second using v1.01-cache-2.11-cpan-e1769b4cff6 )