App-SimpleBackuper
view release on metacpan or search on metacpan
local/lib/perl5/Net/SFTP/Foreign.pm view on Meta::CPAN
contents. Returns the number of elements successfully removed.
This method tries to recover and continue when some error happens.
The options accepted are:
=over 4
=item on_error =E<gt> sub { ... }
This callback is called when some error is occurs. The arguments
passed are the C<$sftp> object and the current entry (a hash
containing the file object details, see C<ls> docs for more
information).
=item wanted =E<gt> ...
=item no_wanted =E<gt> ...
Allows one to select which file system objects have to be deleted.
=back
=item $sftp-E<gt>mget($remote, $localdir, %opts)
=item $sftp-E<gt>mget(\@remote, $localdir, %opts)
X<mget>expands the wildcards on C<$remote> or C<@remote> and retrieves
all the matching files.
For instance:
$sftp->mget(['/etc/hostname.*', '/etc/init.d/*'], '/tmp');
The method accepts all the options valid for L</glob> and for L</get>
(except those that do not make sense :-)
C<$localdir> is optional and defaults to the process current working
directory (C<cwd>).
Files are saved with the same name they have in the remote server
excluding the directory parts.
Note that name collisions are not detected. For instance:
$sftp->mget(["foo/file.txt", "bar/file.txt"], "/tmp")
will transfer the first file to "/tmp/file.txt" and later overwrite it
with the second one. The C<numbered> option can be used to avoid this
issue.
=item $sftp-E<gt>mput($local, $remotedir, %opts)
=item $sftp-E<gt>mput(\@local, $remotedir, %opts)
similar to L</mget> but works in the opposite direction transferring
files from the local side to the remote one.
=item $sftp-E<gt>join(@paths)
returns the given path fragments joined in one path (currently the
remote file system is expected to be UNIX like).
=item $sftp-E<gt>open($path, $flags [, $attrs ])
Sends the C<SSH_FXP_OPEN> command to open a remote file C<$path>,
and returns an open handle on success. On failure returns
C<undef>.
The returned value is a tied handle (see L<Tie::Handle>) that can be
used to access the remote file both with the methods available from
this module and with perl built-ins. For instance:
# reading from the remote file
my $fh1 = $sftp->open("/etc/passwd")
or die $sftp->error;
while (<$fh1>) { ... }
# writing to the remote file
use Net::SFTP::Foreign::Constants qw(:flags);
my $fh2 = $sftp->open("/foo/bar", SSH2_FXF_WRITE|SSH2_FXF_CREAT)
or die $sftp->error;
print $fh2 "printing on the remote file\n";
$sftp->write($fh2, "writing more");
The C<$flags> bitmap determines how to open the remote file as defined
in the SFTP protocol draft (the following constants can be imported
from L<Net::SFTP::Foreign::Constants>):
=over 4
=item SSH2_FXF_READ
Open the file for reading. It is the default mode.
=item SSH2_FXF_WRITE
Open the file for writing. If both this and C<SSH2_FXF_READ> are
specified, the file is opened for both reading and writing.
=item SSH2_FXF_APPEND
Force all writes to append data at the end of the file.
As OpenSSH SFTP server implementation ignores this flag, the module
emulates it (I will appreciate receiving feedback about the
inter-operation of this module with other server implementations when
this flag is used).
=item SSH2_FXF_CREAT
If this flag is specified, then a new file will be created if one does
not already exist.
=item SSH2_FXF_TRUNC
Forces an existing file with the same name to be truncated to zero
length when creating a file. C<SSH2_FXF_CREAT> must also be specified
if this flag is used.
=item SSH2_FXF_EXCL
( run in 0.797 second using v1.01-cache-2.11-cpan-b16cb0d3907 )