--- SSH2.pm_orig Mon Aug 23 20:06:32 2010 +++ SSH2.pm Mon Aug 23 20:36:30 2010 @@ -373,8 +373,18 @@ $self->error(0, "want $block, have $count"), return unless $count == $block; die 'sysread mismatch' unless length $buf == $count; - $self->error(0, "error writing $count bytes to channel"), return - unless $chan->write($buf) == $count; + my $wrote = 0; + while ($wrote >= 0 && $wrote < $count) { + my $wr = $chan->write($buf); + last if $wr < 0; + $wrote += $wr; + $buf = substr $buf, $wr; + } + unless($wrote == $count) { + my @error = $self->error(); + warn "Error writing $count bytes to channel: @error\n"; + return; + } } # send/receive SCP acknowledgement