Subject: | Net::SSH2::SFTP O_APPEND broken |
The first time I run the below program the file is created. The second
time it is run, the text should be appended, but instead the file is
overwritten/truncated. I don't know if this is an error in the perl
module or the underlying libssh2 library.
#!/usr/bin/perl
use strict;
use warnings;
use Net::SSH2;
use Fcntl qw(:DEFAULT);
my $user = 'username';
my $ip = 'xxx.xxx.xxx.xxx';
my $pass = 'password';
print "Connect\n";
my $ssh2 = Net::SSH2->new();
$ssh2->connect($ip) or die "Err connecting: $!";
print "Auth\n";
unless ( $ssh2->auth_password($user, $pass) ) {
die "Err SSH auth: ", $ssh2->error()->[2], "\n";
}
print "Write file\n";
my $sftp = $ssh2->sftp();
my $file = $sftp->open('tmp.txt', O_CREAT|O_APPEND|O_WRONLY)
or die "Err SFTP: " . $ssh2->error()->[2] . "\n";
$file->write("test\n");
$ssh2->disconnect();