Codebase list libnet-sftp-foreign-perl / upstream/1.65+dfsg
[svn-upgrade] new version libnet-sftp-foreign-perl (1.65+dfsg) Nicholas Bamber 12 years ago
9 changed file(s) with 251 addition(s) and 79 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Net::SFTP::Foreign
11
2 1.65 May 17, 2011
3 - die_on_error was broken
4
5 1.64 May 09, 2011
6 - release as stable
7 - document the write_delay and read_ahead options
8 - minor doc corrections
9
10 1.63_10 Apr 13, 2011
11 - workaround bug in perl 5.6 calling STORE in a tied
12 filehandle
13 - solve "not enough arguments for grep" when using an old
14 version of Scalar::Util
15
16 1.63_09 Apr 12, 2011
17 - an error in the handler accessors was adding and useless
18 wrapping layer
19
20 1.63_08 Jan 22, 2011
21 - bad method call inside mkpath corrected (bug report and
22 solution by Adam Pingel)
23
24 1.63_07 Jan 20, 2011
25 - do not override PreferredAuthentication when explicitly set
26 by the user (bug report and solution by Ave Wrigley)
27
28 1.63_06 Dec 10, 2010
29 - redirect_stderr_to_tty was redirecting to the wrong side of
30 the tty (bug report by Russ Brewer)
31
32 1.63_05 Dec 6, 2010
33 - add support for hardlink@openssh.com extension
34 - add die_on_error method
35 - create a new process group for slave ssh process so that
36 signals sent from the terminal are not propagated
37 - better error messages
38
39 1.63_04 Nov 11, 2010
40 - workaround for IPC::Open3::open3 not working with tied file
41 handles on Windows (bug report by Barnabas Bona)
42 - several spelling corrections (contributed by Philippe Bruhat)
43
44 1.63_03 Nov 10, 2010
45 - On some OSs (i.e. AIX) reading/writing from non-blocking fds
46 can result in EAGAIN even when select has indicated that
47 data was available (bug report and patch by Bill Godfrey)
48
49 1.63_02 Nov 2, 2010
50 - Windows backend was not pipelining requests when called from
51 put method
52
53 1.63_01
54 - support for Tectia client added (bug report by Russ Brewer)
255
356 1.62 Oct 5, 2010
457 - _catch_tainted_args was not being imported from helpers (bug
00 --- #YAML:1.0
11 name: Net-SFTP-Foreign
2 version: 1.62
2 version: 1.65
33 abstract: Secure File Transfer Protocol client
44 author:
55 - Salvador Fandino <sfandino@yahoo.com>
3232
3333 COPYRIGHT AND LICENCE
3434
35 Copyright (c) 2005-2010 by Salvador Fandino
35 Copyright (c) 2005-2011 by Salvador Fandino
3636
3737 Copyright (c) 2001 Benjamin Trott, Copyright (c) 2003 David Rolsky.
3838
00 package Net::SFTP::Foreign::Backend::Unix;
11
2 our $VERSION = '1.58_07';
2 our $VERSION = '1.63_07';
33
44 use strict;
55 use warnings;
2121 }
2222
2323 sub _init_transport_streams {
24 my ($self, $sftp) = @_;
24 my (undef, $sftp) = @_;
2525 for my $dir (qw(ssh_in ssh_out)) {
2626 binmode $sftp->{$dir};
2727 my $flags = fcntl($sftp->{$dir}, F_GETFL, 0);
4949 }
5050
5151 sub _open3 {
52 my $backend = shift;
5253 my $sftp = shift;
5354 if (defined $_[2]) {
5455 my $sftp_err = $_[2];
6970 }
7071
7172 sub _init_transport {
72 my ($class, $sftp, $opts) = @_;
73 my ($backend, $sftp, $opts) = @_;
7374
7475 my $transport = delete $opts->{transport};
7576
9798 my $stderr_discard = delete $opts->{stderr_discard};
9899 my $stderr_fh = ($stderr_discard ? undef : delete $opts->{stderr_fh});
99100 my $open2_cmd = delete $opts->{open2_cmd};
101 my $ssh_cmd_interface = delete $opts->{ssh_cmd_interface};
100102
101103 my @open2_cmd;
102104 if (defined $open2_cmd) {
110112 $ssh_cmd = 'ssh' unless defined $ssh_cmd;
111113 @open2_cmd = ($ssh_cmd);
112114
113 my $ssh_cmd_interface = delete $opts->{ssh_cmd_interface};
114115 unless (defined $ssh_cmd_interface) {
115 $ssh_cmd_interface = ( $ssh_cmd =~ /\bplink(?:\.exe)?$/i
116 ? 'plink'
117 : 'ssh');
116 $ssh_cmd_interface = ( $ssh_cmd =~ /\bplink(?:\.exe)?$/i ? 'plink' :
117 $ssh_cmd =~ /\bsshg3$/i ? 'tectia' :
118 'ssh' );
118119 }
119120
120121 my $port = delete $opts->{port};
124125 my $more = delete $opts->{more};
125126 carp "'more' argument looks like if it should be splited first"
126127 if (defined $more and !ref($more) and $more =~ /^-\w\s+\S/);
128 my @more = _ensure_list $more;
127129
128130 if ($ssh_cmd_interface eq 'plink') {
129131 $pass and !$passphrase
133135 elsif ($ssh_cmd_interface eq 'ssh') {
134136 push @open2_cmd, -p => $port if defined $port;
135137 if ($pass and !$passphrase) {
136 push @open2_cmd, (-o => 'NumberOfPasswordPrompts=1',
137 -o => 'PreferredAuthentications=keyboard-interactive,password');
138 push @open2_cmd, -o => 'NumberOfPasswordPrompts=1';
139 push @open2_cmd, -o => 'PreferredAuthentications=keyboard-interactive,password'
140 unless grep { $more[$_] eq '-o' and
141 $more[$_ + 1] =~ /^PreferredAuthentications\W/ } 0..$#more-1;
138142 }
143 }
144 elsif ($ssh_cmd_interface eq 'tectia') {
139145 }
140146 else {
141147 die "Unsupported ssh_cmd_interface '$ssh_cmd_interface'";
142148 }
143149 push @open2_cmd, -l => $user if defined $user;
144 push @open2_cmd, _ensure_list($more) if defined $more;
150 push @open2_cmd, @more;
145151 push @open2_cmd, $host;
146152 push @open2_cmd, ($ssh1 ? "/usr/lib/sftp-server" : -s => 'sftp');
147153 }
148 _debug "ssh cmd: @open2_cmd\n" if ($debug and $debug & 1);
154
155 my $redirect_stderr_to_tty = ( (defined $pass or defined $passphrase) and
156 (delete $opts->{redirect_stderr_to_tty} or
157 $ssh_cmd_interface eq 'tectia' ) );
158
159 $redirect_stderr_to_tty and ($stderr_discard or $stderr_fh)
160 and croak "stderr_discard or stderr_fh can not be used together with password/passphrase "
161 . "authentication when Tectia client is used";
162
163 $debug and $debug & 1 and _debug "ssh cmd: @open2_cmd\n";
149164
150165 %$opts and return; # Net::SFTP::Foreign will find the
151166 # unhandled options and croak
155170 }
156171
157172 if ($stderr_discard) {
158 $stderr_fh = $class->_open_dev_null($sftp) or return;
173 $stderr_fh = $backend->_open_dev_null($sftp) or return;
159174 }
160175
161176 my $this_pid = $$;
184199 $expect->raw_pty(1);
185200 $expect->log_user($expect_log_user);
186201
187 $child = _open3($sftp, $sftp->{ssh_in}, $sftp->{ssh_out}, $stderr_fh, '-');
202 $redirect_stderr_to_tty and $stderr_fh = $pty->slave;
203
204 $child = $backend->_open3($sftp, $sftp->{ssh_in}, $sftp->{ssh_out}, $stderr_fh, '-');
188205
189206 if (defined $child and !$child) {
190207 $pty->make_slave_controlling_terminal;
195212 # $pty->close_slave();
196213 }
197214 else {
215 $redirect_stderr_to_tty and
216 croak "In order to support password/passphrase authentication with the Tectia client, " .
217 "IPC::Open3 version 1.0105 is required (current version is $IPC::Open3::VERSION)";
198218 $expect = Expect->new;
199219 $expect->raw_pty(1);
200220 $expect->log_user($expect_log_user);
230250 $expect->close_slave();
231251 }
232252 else {
233 $sftp->{pid} = _open3($sftp, $sftp->{ssh_in}, $sftp->{ssh_out}, $stderr_fh, @open2_cmd);
253 $sftp->{pid} = $backend->_open3($sftp, $sftp->{ssh_in}, $sftp->{ssh_out}, $stderr_fh, @open2_cmd);
234254 _ipc_open2_bug_workaround $this_pid;
235255
236256 unless (defined $sftp->{pid}) {
237257 $sftp->_conn_failed("Bad ssh command", $!);
238258 return;
239259 }
240 }
241 }
242 $class->_init_transport_streams($sftp);
260 # do not propagate signals sent from the terminal to the
261 # slave SSH:
262 eval {
263 setpgrp($sftp->{pid}, 0);
264 };
265 }
266 }
267 $backend->_init_transport_streams($sftp);
243268 }
244269
245270
246271 sub _do_io {
247 my ($self, $sftp, $timeout) = @_;
272 my (undef, $sftp, $timeout) = @_;
248273
249274 $debug and $debug & 32 and _debug(sprintf "_do_io connected: %s", $sftp->{_connected} || 0);
250275
294319 64 * 1024, $!);
295320 $debug & 2048 and $written and _hexdump(substr($$bout, 0, $written));
296321 }
297 unless ($written) {
322 if ($written) {
323 substr($$bout, 0, $written, '');
324 }
325 elsif ($! != Errno::EAGAIN() and $! != Errno::EINTR()) {
298326 $sftp->_conn_lost;
299327 return undef;
300328 }
301 substr($$bout, 0, $written, '');
302329 }
303330 if (vec($rv1, $fnoin, 1)) {
304331 my $read = sysread($sftp->{ssh_in}, $$bin, 64 * 1024, length($$bin));
309336 $!);
310337 $debug & 1024 and $read and _hexdump(substr($$bin, -$read));
311338 }
312 unless ($read) {
339 if (!$read and $! != Errno::EAGAIN() and $! != Errno::EINTR()) {
313340 $sftp->_conn_lost;
314341 return undef;
315342 }
317344 }
318345 else {
319346 $debug and $debug & 32 and _debug "_do_io select failed: $!";
320 next if ($n < 0 and $! == Errno::EINTR());
347 next if ($n < 0 and ($! == Errno::EINTR() or $! == Errno::EAGAIN()));
321348 return undef;
322349 }
323350 }
00 package Net::SFTP::Foreign::Backend::Windows;
11
2 our $VERSION = '1.58_05';
2 our $VERSION = '1.63_05';
33
44 use strict;
55 use warnings;
1919 }
2020
2121 sub _init_transport_streams {
22 my ($self, $sftp) = @_;
22 my ($backend, $sftp) = @_;
2323 binmode $sftp->{ssh_in};
2424 binmode $sftp->{ssh_out};
2525 }
2727 sub _open_dev_null {
2828 my $sftp = shift;
2929 my $dev_null;
30 unless (open $dev_null, '>', "NUL:") {
31 $sftp->_conn_failed("Unable to redirect stderr to NUL:");
30 unless (open $dev_null, '>', 'NUL:') {
31 $sftp->_conn_failed("Unable to redirect stderr for slave SSH process to NUL: $!");
3232 return;
3333 }
3434 $dev_null
35 }
36
37 # workaround for IPC::Open3 not working with tied filehandles even
38 # when they implement FILENO
39 sub _open3 {
40 my $backend = shift;
41 my $sftp = shift;
42 if (tied(*STDERR)) {
43 my $fn = eval { defined $_[2] ? fileno $_[2] : fileno *STDERR };
44 unless (defined $fn and $fn >= 0) {
45 $sftp->_conn_failed("STDERR or stderr_fh is not a real file handle: " . (length $@ ? $@ : $!));
46 return;
47 }
48 local *STDERR;
49 unless (open STDERR, ">&=$fn") {
50 $sftp->_conn_failed("Unable to reattach STDERR to fd $fn: $!");
51 return;
52 }
53 $backend->SUPER::_open3($sftp, @_);
54 }
55 else {
56 $backend->SUPER::_open3($sftp, @_);
57 }
3558 }
3659
3760 sub _sysreadn {
5073 }
5174
5275 sub _do_io {
53 my ($self, $sftp, $timeout) = @_;
76 my ($backend, $sftp, $timeout) = @_;
5477
5578 return undef unless $sftp->{_connected};
5679
6689 substr($$bout, 0, $written, "");
6790 }
6891
92 defined $timeout and $timeout <= 0 and return;
93
6994 _sysreadn($sftp, 4) or return undef;
7095
7196 my $len = 4 + unpack N => $$bin;
7297 if ($len > 256 * 1024) {
73 $sftp->_set_status(SSH2_FX_BAD_MESSAGE);
74 $sftp->_set_error(SFTP_ERR_REMOTE_BAD_MESSAGE,
75 "bad remote message received");
76 return undef;
98 $sftp->_set_status(SSH2_FX_BAD_MESSAGE);
99 $sftp->_set_error(SFTP_ERR_REMOTE_BAD_MESSAGE,
100 "bad remote message received");
101 return undef;
77102 }
78103 _sysreadn($sftp, $len);
79104 }
00 package Net::SFTP::Foreign::Common;
11
2 our $VERSION = '1.57';
2 our $VERSION = '1.65';
33
44 use strict;
55 use warnings;
7676 }
7777
7878 sub error { shift->{_error} }
79
80 sub die_on_error {
81 my $sftp = shift;
82 $sftp->{_error} and croak(@_ ? "@_: $sftp->{_error}" : $sftp->{_error});
83 }
7984
8085 sub _set_errno {
8186 my $sftp = shift;
00 package Net::SFTP::Foreign::Constants;
11
2 our $VERSION = '1.52';
2 our $VERSION = '1.63_05';
33
44 use strict;
55 use warnings;
116116 SFTP_ERR_REMOTE_STATVFS_FAILED => 48,
117117 SFTP_ERR_REMOTE_FSTATVFS_FAILED => 49,
118118 SFTP_ERR_PASSWORD_AUTHENTICATION_FAILED => 50,
119 SFTP_ERR_REMOTE_HARDLINK_FAILED => 51,
119120 );
120121
121122 for my $key (keys %constants) {
214215 C<SFTP_ERR_REMOTE_REALPATH_FAILED>, C<SFTP_ERR_REMOTE_REMOVE_FAILED>,
215216 C<SFTP_ERR_REMOTE_RENAME_FAILED>, C<SFTP_ERR_REMOTE_RMDIR_FAILED>,
216217 C<SFTP_ERR_REMOTE_READLINK_FAILED>, C<SFTP_ERR_REMOTE_SYMLINK_FAILED>,
217 C<SFTP_ERR_REMOTE_SETSTAT_FAILED>, C<SFTP_ERR_REMOTE_STAT_FAILED> and
218 C<SFTP_ERR_REMOTE_WRITE_FAILED>.
218 C<SFTP_ERR_REMOTE_SETSTAT_FAILED>, C<SFTP_ERR_REMOTE_STAT_FAILED>,
219 C<SFTP_ERR_REMOTE_WRITE_FAILED> and
220 C<SFTP_ERR_REMOTE_HARDLINK_FAILED>.
219221
220222 Note: these constants are not defined on the SFTP draft.
221223
206206 my $i;
207207 for (@_) {
208208 next unless $i++;
209 if (tainted $_) {
209 if (tainted($_)) {
210210 my (undef, undef, undef, $subn) = caller 1;
211211 my $msg = ( $subn =~ /::([a-z]\w*)$/
212212 ? "Insecure argument '$_' on '$1' method call"
214214 _tcroak($msg);
215215 }
216216 elsif (ref($_)) {
217 for (grep tainted $_,
217 for (grep tainted($_),
218218 do { local ($@, $SIG{__DIE__}); eval { values %$_ }}) {
219219 my (undef, undef, undef, $subn) = caller 1;
220220 my $msg = ( $subn =~ /::([a-z]\w*)$/
00 package Net::SFTP::Foreign;
11
2 our $VERSION = '1.62';
2 our $VERSION = '1.65';
33
44 use strict;
55 use warnings;
187187 $sftp->{_queue_size} = delete $opts{queue_size} || $defs{queue_size} || 32;
188188 $sftp->{_read_ahead} = $defs{read_ahead} || $sftp->{_block_size} * 4;
189189 $sftp->{_write_delay} = $defs{write_delay} || $sftp->{_block_size} * 8;
190 $sftp->{_timeout} = delete $opts{timeout};
191190 $sftp->{_autoflush} = delete $opts{autoflush};
192191 $sftp->{_late_set_perm} = delete $opts{late_set_perm};
193192 $sftp->{_dirty_cleanup} = delete $opts{dirty_cleanup};
193
194 $sftp->{_timeout} = delete $opts{timeout};
195 defined $sftp->{_timeout} and $sftp->{_timeout} <= 0 and croak "invalid timeout";
196
194197 $sftp->{_fs_encoding} = delete $opts{fs_encoding};
195
196198 if (defined $sftp->{_fs_encoding}) {
197199 $] < 5.008
198200 and carp "fs_encoding feature is not supported in this perl version $]";
10231025 last;
10241026 }
10251027 unless (length $path) {
1026 $sftp->set_error(SFTP_ERR_REMOTE_MKDIR_FAILED,
1027 "Unable to make path, bad root");
1028 $sftp->_set_error(SFTP_ERR_REMOTE_MKDIR_FAILED,
1029 "Unable to make path, bad root");
10281030 return undef;
10291031 }
10301032 unshift @path, $p;
12991301
13001302 $sftp->_check_status_ok($id, SFTP_ERR_REMOTE_SYMLINK_FAILED,
13011303 "Couldn't create symlink '$sl' pointing to '$target'");
1304 }
1305
1306 sub hardlink {
1307 @_ == 3 or croak 'Usage: $sftp->hardlink($hl, $target)';
1308 ${^TAINT} and &_catch_tainted_args;
1309
1310 my ($sftp, $hl, $target) = @_;
1311
1312 $sftp->_check_extension('hardlink@openssh.com' => 1,
1313 SFTP_ERR_REMOTE_HARDLINK_FAILED,
1314 "hardlink failed")
1315 or return undef;
1316 $hl = $sftp->_rel2abs($hl);
1317 $target = $sftp->_rel2abs($target);
1318
1319 my $id = $sftp->_queue_new_msg(SSH2_FXP_EXTENDED,
1320 str => 'hardlink@openssh.com',
1321 str => $sftp->_fs_encode($target),
1322 str => $sftp->_fs_encode($hl));
1323 $sftp->_check_status_ok($id, SFTP_ERR_REMOTE_HARDLINK_FAILED,
1324 "Couldn't create hardlink '$hl' pointing to '$target'");
13021325 }
13031326
13041327 sub _gen_save_status_method {
27642787 my $gen_accessor = sub {
27652788 my $ix = shift;
27662789 sub {
2767 my $st = *{shift()}->{ARRAY};
2790 my $st = *{shift()}{ARRAY};
27682791 if (@_) {
27692792 $st->[$ix] = shift;
27702793 }
28142837
28152838 my $self = Symbol::gensym;
28162839 bless $self, $class;
2840 *$self = [ $sftp, $rid, 0, $flags, @_];
28172841 tie *$self, $self;
2818 *{$self}->{ARRAY} = [ $sftp, $rid, 0, $flags, @_];
28192842
28202843 $self;
28212844 }
28222845
28232846 sub _close {
28242847 my $self = shift;
2825 @{*$self->{ARRAY}} = ();
2848 @{*{$self}{ARRAY}} = ();
28262849 }
28272850
28282851 sub _check {
2829 return 1 if defined(*{shift()}->{ARRAY}[0]);
2852 return 1 if defined(*{shift()}{ARRAY}[0]);
28302853 $! = Errno::EBADF;
28312854 undef;
28322855 }
28402863 "-1:sftp(0x$hrid)"
28412864 }
28422865
2843 sub _sftp { *{shift()}->{ARRAY}[0] }
2844 sub _rid { *{shift()}->{ARRAY}[1] }
2866 sub _sftp { *{shift()}{ARRAY}[0] }
2867 sub _rid { *{shift()}{ARRAY}[1] }
28452868
28462869 * _pos = $gen_accessor->(2);
28472870
28482871 sub _inc_pos {
28492872 my ($self, $inc) = @_;
2850 *{shift()}->{ARRAY}[2] += $inc;
2873 *{shift()}{ARRAY}[2] += $inc;
28512874 }
28522875
28532876
28542877 my %flag_bit = (append => 0x1);
28552878
28562879 sub _flag {
2857 my $st = *{shift()}->{ARRAY};
2880 my $st = *{shift()}{ARRAY};
28582881 my $fn = shift;
28592882 my $flag = $flag_bit{$fn};
28602883 Carp::croak("unknown flag $fn") unless defined $flag;
29072930
29082931 sub _check_is_file {}
29092932
2910 sub _bin { \(*{shift()}->{ARRAY}[4]) }
2911 sub _bout { \(*{shift()}->{ARRAY}[5]) }
2933 sub _bin { \(*{shift()}{ARRAY}[4]) }
2934 sub _bout { \(*{shift()}{ARRAY}[5]) }
29122935
29132936 sub WRITE {
29142937 my ($self, undef, $length, $offset) = @_;
30053028
30063029 sub _check_is_dir {}
30073030
3008 sub _cache { *{shift()}->{ARRAY}[4] }
3031 sub _cache { *{shift()}{ARRAY}[4] }
30093032
30103033 *CLOSEDIR = $gen_proxy_method->('closedir');
30113034 *READDIR = $gen_proxy_method->('_readdir');
30413064
30423065 use Net::SFTP::Foreign;
30433066 my $sftp = Net::SFTP::Foreign->new($host);
3044 $sftp->error and
3045 die "Unable to stablish SFTP connection: " . $sftp->error;
3067 $sftp->die_on_error("Unable to establish SFTP connection");
30463068
30473069 $sftp->setcwd($path) or die "unable to change cwd: " . $sftp->error;
30483070
30783100
30793101 Well, both modules have their pros and cons:
30803102
3081 Net::SFTP::Foreign does not requiere a bunch of additional modules and
3103 Net::SFTP::Foreign does not require a bunch of additional modules and
30823104 external libraries to work, just the OpenBSD SSH client (or any other
30833105 client compatible enough).
30843106
31353157 constructor call:
31363158
31373159 my $sftp = Net::SFTP::Foreign->new(...);
3138 $sftp->error and die "SSH connection failed: " . $sftp->error;
3160 $sftp->die_on_error("SSH connection failed");
31393161
31403162 C<%args> can contain:
31413163
31723194 more => "-i $key" # wrong!!!
31733195 more => [-i => $key] # right
31743196
3175 =item ssh_cmd_interface =E<gt> 'plink' or 'ssh'
3197 =item ssh_cmd_interface =E<gt> 'plink' or 'ssh' or 'tectia'
31763198
31773199 declares the command line interface that the SSH client used to
3178 connect to the remote host understands. Currently C<plink> and C<ssh>
3179 are supported.
3200 connect to the remote host understands. Currently C<plink>, C<ssh> and
3201 C<tectia> are supported.
31803202
31813203 This option would be rarely required as the module infers the
31823204 interface from the SSH command name.
3183
3184 =item autoflush =E<gt> $bool
3185
3186 by default, and for performance reasons, write operations are cached,
3187 and only when the write buffer becomes big enough is the data written to
3188 the remote file. Setting this flag makes the write operations inmediate.
31893205
31903206 =item timeout =E<gt> $seconds
31913207
32073223
32083224 For instance:
32093225
3210 $sftp = Net::SFTP::Foreign->new('user@host', fs_encoding => latin1);
3226 $sftp = Net::SFTP::Foreign->new('user@host', fs_encoding => 'latin1');
32113227
32123228 will convert any path name passed to any method in this package to its
32133229 C<latin1> representation before sending it to the remote side.
33083324 default C<block_size> and C<queue_size> used for read and write
33093325 operations (see the C<put> or C<get> documentation).
33103326
3327 =item autoflush =E<gt> $bool
3328
3329 by default, and for performance reasons, write operations are cached,
3330 and only when the write buffer becomes big enough is the data written to
3331 the remote file. Setting this flag makes the write operations inmediate.
3332
3333 =item write_delay =E<gt> $bytes
3334
3335 This option determines how many bytes are buffered before the real
3336 SFTP write operation is performed.
3337
3338 =item read_ahead =E<gt> $bytes
3339
3340 On read operations this option determines how many bytes to read in
3341 advance so that later read operations can be fulfilled from the
3342 buffer.
3343
3344 Using a high value will increase the performance of the module for a
3345 sequential reads access pattern but degrade it for a short random
3346 reads access pattern. It can also cause synchronization problems if
3347 the file is concurrently modified by other parties (L</flush> can be
3348 used to discard all the data inside the read buffer on demand).
3349
3350 The default value is set dynamically considering some runtime
3351 parameters and given options, though it tends to favor the sequential
3352 read access pattern.
3353
33113354 =item autodisconnect =E<gt> $ad
33123355
33133356 by default, the SSH connection is closed from the DESTROY method when
33253368
33263369 Never try to disconnect this object when exiting from any process.
33273370
3328 On most operative systems, the SSH process will exit when the last
3371 On most operating systems, the SSH process will exit when the last
33293372 process connected to it ends, but this is not guaranteed.
33303373
33313374 =item 1
33683411
33693412 See L<Net::SFTP::Foreign::Constants> for a list of possible error
33703413 codes and how to import them on your scripts.
3414
3415 =item $sftp-E<gt>die_on_error($msg)
3416
3417 Convenience method:
3418
3419 $sftp->die_on_error("Something bad happened");
3420 # is a shortcut for...
3421 $sftp->error and die "Something bad happened: " . $sftp->error;
33713422
33723423 =item $sftp-E<gt>status
33733424
36823733
36833734 =item wanted =E<gt> qr/.../
36843735
3685 Only elements which filename match the regular expresion are included
3736 Only elements which filename match the regular expression are included
36863737 on the listing.
36873738
36883739 =item wanted =E<gt> sub {...}
38093860
38103861 =item ordered =E<gt> 1
38113862
3812 By default, the file system is searched in an implementation dependant
3863 By default, the file system is searched in an implementation dependent
38133864 order (actually optimized for low memory comsumption). If this option
38143865 is included, the file system is searched in a deep-first, sorted by
38153866 filename fashion.
38933944
38943945 =item strict_leading_dot =E<gt> 0
38953946
3896 by default, a dot character at the begining of a file or directory
3947 by default, a dot character at the beginning of a file or directory
38973948 name is not matched by willcards (C<*> or C<?>). Setting this flags to
38983949 a false value changes this behaviour.
38993950
42744325 =item $sftp-E<gt>opendir($path)
42754326
42764327 Sends a C<SSH_FXP_OPENDIR> command to open the remote directory
4277 C<$path>, and returns an open handle on success (unfortunatelly,
4328 C<$path>, and returns an open handle on success (unfortunately,
42784329 current versions of perl does not support directory operations via
42794330 tied handles, so it is not possible to use the returned handle as a
42804331 native one).
44084459 it. Use C<realpath> to normalize it:
44094460
44104461 $sftp->symlink("foo.lnk" => $sftp->realpath("../bar"))
4462
4463 =item $sftp-E<gt>hardlink($hl, $target)
4464
4465 Creates a hardlink on the server.
4466
4467 This command requires support for the 'hardlink@openssh.com' extension
4468 on the server (available in OpenSSH from version 5.7).
44114469
44124470 =item $sftp-E<gt>statvfs($path)
44134471
45604618 my $sftp = Net::SFTP::Foreign->new('foo@bar',
45614619 ssh_cmd => 'plink',
45624620 more => [-pw => $password]);
4563 $sftp->error and die $sftp->error;
4621 $sftp->die_on_error;
45644622
45654623 =item Plink
45664624
45764634 B<Q>: put fails with the following error:
45774635
45784636 Couldn't setstat remote file (fsetstat): The requested operation
4579 cannot be performed because there is a file transfer in progress.
4637 cannot be performed because there is a file transfer in progress.
45804638
45814639 B<A>: Try passing the C<late_set_perm> option to the put method:
45824640
46464704 B<A>: That probably means that the public key from the remote server
46474705 is not stored in the C<~/.ssh/known_hosts> file. Run an SSH Connection
46484706 from the command line as the same user as the script and answer C<yes>
4649 when asked to confirm the key suplied.
4707 when asked to confirm the key supplied.
46504708
46514709 Example:
46524710
46824740
46834741 =item - Dirty cleanup:
46844742
4685 On some operative systems, closing the pipes used to comunicate with
4743 On some operating systems, closing the pipes used to comunicate with
46864744 the slave SSH process does not terminate it and a work around has to
46874745 be applied. If you find that your scripts hung when the $sftp object
46884746 gets out of scope, try setting C<$Net::SFTP::Foreign::dirty_cleanup>
47034761
47044762 Also, the following features should be considered experimental:
47054763
4764 - support for Tectia server
4765
47064766 - redirecting SSH stderr stream
47074767
47084768 - multi-backend support
47544814
47554815 =head1 COPYRIGHT
47564816
4757 Copyright (c) 2005-2010 Salvador FandiE<ntilde>o (sfandino@yahoo.com).
4817 Copyright (c) 2005-2011 Salvador FandiE<ntilde>o (sfandino@yahoo.com).
47584818
47594819 Copyright (c) 2001 Benjamin Trott, Copyright (c) 2003 David Rolsky.
47604820