CPAN::Forum
Net-SSH2 - Does unlink work in a chrooted environment?
| Posted on Wed Feb 13 23:56:31 2008 by ncalsmitty1369 |
| Does unlink work in a chrooted environment? |
|
Hi,
I was doing some testing with the code below. I found that the code would work to unlink files in some directories, other then /tmp. I also found that the same code would not work to unlink files on a remote server if you were dropped into a chrooted environment, even if you had the proper permissions to remove files. If failed with the following error:
Couldn't remove /remote_server_dir/some_file: Invalid argument at script_name.pl.
Does anyone know if I am just doing things wrong in the code below to cause that error? Is the outcome to be expected with a remote server chrooted environment? Are there work arounds, other then just shell scripting?
The version of Net::SSH2 tested was v0.18.
Thanks,
M
use strict;
use warnings;
use Net::SSH2;
my $rem_host = 'xxx.xxx.xxx.xxx';
my $rem_dir = '/export/ssh2_test/testing';
my $username = 'username';
my $password = 'password';
my $local_dir = '/export/scripts/ssh2_testing/temp';
my $rem_name;
my $rem_size;
## connect to remote server with perl and ssh2 module ##
my $ssh2 = Net::SSH2->new();
$ssh2->connect($rem_host) or die "Could not connect to $rem_host: $!";
$ssh2->auth_password($username,$password) or
die "Could not login to $rem_host: $!";
## uncomment line below to turn on debugging. ##
$ssh2->debug(1);
## open sftp object ##
my $get_xml = $ssh2->sftp();
## get list of files in the /Outbound dir ##
my $list = $get_xml->opendir($rem_dir) or die "Couldn't open dir $rem_dir: $!";
while (my $ref = $list->read()) {
next if ( $ref->{name} =~ m/^\.\.?/ );
next if ( $ref->{size} =~ m/4096/ ); ## exclude dirs
print "name: $ref->{name}\n";
$rem_name = $ref->{name};
my $there = "$rem_dir/$rem_name";
my $here = "$local_dir/$rem_name";
open WRITE_LOCAL_FILE,">$here" or die "Couldn't open $here: $!";
sleep(1);
## read $rem_file and write locally ##
my $open_rem_file = $get_xml->open($there) or
die "Couldn't open $there: $!";
my $buff;
while ( $open_rem_file->read($buff,4096) ) {
print WRITE_LOCAL_FILE $buff;
}
close WRITE_LOCAL_FILE;
## code to remove the downloaded file ##
$get_xml->unlink($there) or die "Couldn't remove $there: $!";
}
$ssh2->disconnect() or die "Couldn't do disconnect on ssh2: $!";
|
| Write a response |
(2)
]