Skip Menu |

This queue is for tickets about the Net-SFTP CPAN distribution.

Report information
The Basics
Id: 27586
Status: open
Priority: 0/
Queue: Net-SFTP

People
Owner: Nobody in particular
Requestors: arnotts [...] gsicommerce.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.10
Fixed in: (no value)



Subject: get() does not return correct status for success
When Net::SFTP get() function is called with a local file specified, the code returns an empty string, instead of the file contents. $status = $ftp->get($from,$to); However this contradicts the documentation, which states: Show quoted text
> If get is called in a non-void context, returns the contents of
$remote > (as well as writing them to $local, if $local is provided. Undef is Show quoted text
> returned on failure.
This is a different action from Net::FTP, where the local filename is returned on success. I feel the Net::FTP method is much better than returning an empty string on success... and much easier to code for success/failure. Steven
Patch to fix this: Index: usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm =================================================================== --- usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm +++ usr/lib/perl5/site_perl/5.8.8/Net/SFTP.pm @@ -407,7 +407,9 @@ if ($local) { print FH $data; } - elsif ($want) { + # changed from being elsif to else as the elsif contradicts the + # docs. see http://rt.cpan.org/Public/Bug/Display.html?id=27586 + if ($want) { $ret .= $data; } $offset += $len;
the reason it returns the empty string is because Net::SFTP uses wantarray to determine void context, which is wrong, wrong, wrong. wantarray, as is explicitly implied by its name determines LIST context. if the documentation were to accurately reflect the API, it would read: If get is called in a list context, returns the contents of $remote (as well as writing them to $local, if $local is provided. Undef is returned on failure. wantarray is a tumor on the face of perl and should be avoided. the author should change the API to return a status code or status object from ->get. On Thu Jun 14 17:08:31 2007, ArcticSnowman wrote: Show quoted text
> When Net::SFTP get() function is called with a local file specified,
the Show quoted text
> code returns an empty string, instead of the file contents. > > $status = $ftp->get($from,$to); > > However this contradicts the documentation, which states: >
> > If get is called in a non-void context, returns the contents of
> $remote > (as well as writing them to $local, if $local is provided. > Undef is
> > returned on failure.
> > This is a different action from Net::FTP, where the local filename is > returned on success. > > I feel the Net::FTP method is much better than returning an empty
string Show quoted text
> on success... and much easier to code for success/failure. > > Steven
On Tue May 04 14:12:51 2010, DIZ wrote: Show quoted text
> the reason it returns the empty string is because Net::SFTP uses > wantarray to determine void context, which is wrong, wrong, wrong. > wantarray, as is explicitly implied by its name determines LIST > context.
ignore me. i didn't realize wantarray goes three ways. this is still a bug, but the previous poster illustrated why in the patch he provided. -mike