App-SimpleBackuper
view release on metacpan or search on metacpan
local/lib/perl5/Net/SFTP/Foreign.pm view on Meta::CPAN
=item $sftp-E<gt>ls($remote, %opts)
Fetches a listing of the remote directory C<$remote>. If C<$remote> is
not given, the current remote working directory is listed.
Returns a reference to a list of entries. Every entry is a reference
to a hash with three keys: C<filename>, the name of the entry;
C<longname>, an entry in a "long" listing like C<ls -l>; and C<a>, a
L<Net::SFTP::Foreign::Attributes> object containing file atime, mtime,
permissions and size.
my $ls = $sftp->ls('/home/foo')
or die "unable to retrieve directory: ".$sftp->error;
print "$_->{filename}\n" for (@$ls);
The options accepted by this method are as follows (note that usage of
some of them can degrade the method performance when reading large
directories):
=over 4
=item wanted =E<gt> qr/.../
Only elements whose name matches the given regular expression are
included on the listing.
=item wanted =E<gt> sub {...}
Only elements for which the callback returns a true value are included
on the listing. The callback is called with two arguments: the
C<$sftp> object and the current entry (a hash reference as described
before). For instance:
use Fcntl ':mode';
my $files = $sftp->ls ( '/home/hommer',
wanted => sub {
my $entry = $_[1];
S_ISREG($entry->{a}->perm)
} )
or die "ls failed: ".$sftp->error;
=item no_wanted =E<gt> qr/.../
=item no_wanted =E<gt> sub {...}
those options have the opposite result to their C<wanted> counterparts:
my $no_hidden = $sftp->ls( '/home/homer',
no_wanted => qr/^\./ )
or die "ls failed";
When both C<no_wanted> and C<wanted> rules are used, the C<no_wanted>
rule is applied first and then the C<wanted> one (order is important
if the callbacks have side effects, experiment!).
=item ordered =E<gt> 1
the list of entries is ordered by filename.
=item follow_links =E<gt> 1
by default, the attributes on the listing correspond to a C<lstat>
operation, setting this option causes the method to perform C<stat>
requests instead. C<lstat> attributes will still appear for links
pointing to non existent places.
=item atomic_readdir =E<gt> 1
reading a directory is not an atomic SFTP operation and the protocol
draft does not define what happens if C<readdir> requests and write
operations (for instance C<remove> or C<open>) affecting the same
directory are intermixed.
This flag ensures that no callback call (C<wanted>, C<no_wanted>) is
performed in the middle of reading a directory and has to be set if
any of the callbacks can modify the file system.
=item realpath =E<gt> 1
for every file object, performs a realpath operation and populates the
C<realpath> entry.
=item names_only =E<gt> 1
makes the method return a simple array containing the file names from
the remote directory only. For instance, these two sentences are
equivalent:
my @ls1 = @{ $sftp->ls('.', names_only => 1) };
my @ls2 = map { $_->{filename} } @{$sftp->ls('.')};
=back
=item $sftp-E<gt>find($path, %opts)
=item $sftp-E<gt>find(\@paths, %opts)
X<find>Does a recursive search over the given directory C<$path> (or
directories C<@path>) and returns a list of the entries found or the
total number of them on scalar context.
Every entry is a reference to a hash with two keys: C<filename>, the
full path of the entry; and C<a>, a L<Net::SFTP::Foreign::Attributes>
object containing file atime, mtime, permissions and size.
This method tries to recover and continue under error conditions.
The options accepted:
=over 4
=item on_error =E<gt> sub { ... }
the callback is called when some error is detected, two arguments are
passed: the C<$sftp> object and the entry that was being processed
when the error happened. For instance:
my @find = $sftp->find( '/',
on_error => sub {
my ($sftp, $e) = @_;
print STDERR "error processing $e->{filename}: "
. $sftp->error;
} );
=item realpath =E<gt> 1
calls method C<realpath> for every entry, the result is stored under
the key C<realpath>. This option slows down the process as a new
remote query is performed for every entry, specially on networks with
high latency.
=item follow_links =E<gt> 1
By default symbolic links are not resolved and appear as that on the
final listing. This option causes then to be resolved and substituted
by the target file system object. Dangling links are ignored, though
they generate a call to the C<on_error> callback when stat fails on
them.
Following symbolic links can introduce loops on the search. Infinite
loops are detected and broken but files can still appear repeated on
the final listing under different names unless the option C<realpath>
is also active.
=item ordered =E<gt> 1
By default, the file system is searched in an implementation dependent
order (actually optimized for low memory consumption). If this option
is included, the file system is searched in a deep-first, sorted by
filename fashion.
=item wanted =E<gt> qr/.../
=item wanted =E<gt> sub { ... }
=item no_wanted =E<gt> qr/.../
=item no_wanted =E<gt> sub { ... }
These options have the same effect as on the C<ls> method, allowing to
filter out unwanted entries (note that filename keys contain B<full
paths> here).
The callbacks can also be used to perform some action instead of
creating the full listing of entries in memory (that could use huge
amounts of RAM for big file trees):
$sftp->find($src_dir,
wanted => sub {
my $fn = $_[1]->{filename}
print "$fn\n" if $fn =~ /\.p[ml]$/;
return undef # so it is discarded
});
=item descend =E<gt> qr/.../
=item descend =E<gt> sub { ... }
=item no_descend =E<gt> qr/.../
=item no_descend =E<gt> sub { ... }
These options, similar to the C<wanted> ones, allow one to prune the
search, discarding full subdirectories. For instance:
use Fcntl ':mode';
my @files = $sftp->find( '.',
no_descend => qr/\.svn$/,
wanted => sub {
S_ISREG($_[1]->{a}->perm)
} );
C<descend> and C<wanted> rules are unrelated. A directory discarded by
a C<wanted> rule will still be recursively searched unless it is also
discarded on a C<descend> rule and vice versa.
=item atomic_readdir =E<gt> 1
see C<ls> method documentation.
=item names_only =E<gt> 1
makes the method return a list with the names of the files only (see C<ls>
method documentation).
equivalent:
my $ls1 = $sftp->ls('.', names_only => 1);
=back
=item $sftp-E<gt>glob($pattern, %opts)
X<glob>performs a remote glob and returns the list of matching entries
in the same format as the L</find> method.
This method tries to recover and continue under error conditions.
The given pattern can be a UNIX style pattern (see L<glob(7)>) or a
Regexp object (i.e C<qr/foo/>). In the later case, only files on the
current working directory will be matched against the Regexp.
Accepted options:
( run in 1.867 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )