develooper Front page | perl.beginners | Postings from July 2010

net::sftp ls() error

Thread Next
July 9, 2010 09:42
net::sftp ls() error
Message ID:
Hello,  I'm trying to perform an ls() on a remote nested directory  
using the Net::SFTP module.  It's throwing back a strange error.  If I  
do an ls() at the root dir everything comes back fine - it's just the  
nested dir that has an issue.

Here is my code:


use Net::SFTP;
use GnuPG qw( :algo );
use File::Copy;

my $gpg_homedir = "/home/fnbosftp/.gnupg";
my $host = `/etc/db_auth fnbo hostname`;
our $dropoff = "/home/fnbosftp/dropoff";
my $shred = "/usr/bin/shred -u";
my $backup_dir = "/home/fnbosftp/backup";
our $log_file = "/var/log/fnbo.log";
my $application = "ApplicationJava";
my $pickup_dir = 'out/03050';

# First, get the files

sub get_files
         my ($pickup_dir,$host) = @_;
         my $username = `/etc/db_auth fnbo username`;
         my $password = `/etc/db_auth fnbo password`;

         my %ssh_args = (user => "$username", password => "$password",  
debug => "1", ssh_args => [protocol => 2]);
         my $sftp = Net::SFTP->new($host, %ssh_args) or logger("Unable  
to connect to $host: $!");
         my $status = $sftp->status;

         $sftp->ls($pickup_dir,sub { print $_[0]->{filename}, "\n" });


sub logger
         my $message = shift;

         open(FH,">>","$log_file") or die "Unable to open log file: $! 
         print FH localtime(). " $message\n";

So if I set $pickup_dir = "." everything returns as expected.  Here is  
the debug output:

sftp01: Reading configuration data /root/.ssh/config
sftp01: Reading configuration data /etc/ssh_config
sftp01: Allocated local port 1023.
sftp01: Connecting to, port 22.
sftp01: Remote protocol version 2.0, remote software version 0
sftp01: Net::SSH::Perl Version 1.34, protocol version 2.0. No compat match: 0
sftp01: Connection established.
sftp01: Sent key-exchange init (KEXINIT), wait response.
sftp01: Algorithms, c->s: 3des-cbc hmac-sha1 none
sftp01: Algorithms, s->c: 3des-cbc hmac-sha1 none
sftp01: Entering Diffie-Hellman Group 1 key exchange.
sftp01: Sent DH public key, waiting for reply.
sftp01: Received host key, type 'ssh-dss'.
sftp01: Host '' is known and matches the host key.
sftp01: Computing shared secret key.
sftp01: Verifying server signature.
sftp01: Waiting for NEWKEYS message.
sftp01: Send NEWKEYS.
sftp01: Enabling encryption/MAC/compression.
sftp01: Sending request for user-authentication service.
sftp01: Service accepted: ssh-userauth.
sftp01: Trying empty user-authentication request.
sftp01: Authentication methods that can continue: publickey,password.
sftp01: Next method to try is publickey.
sftp01: Next method to try is password.
sftp01: Trying password authentication.
sftp01: Login completed, opening dummy shell channel.
sftp01: channel 0: new [client-session]
sftp01: Requesting channel_open for channel 0.
sftp01: channel 0: open confirm rwindow 300000 rmax 30000
sftp01: channel 1: new [client-session]
sftp01: Requesting channel_open for channel 1.
sftp01: Sending subsystem: sftp
sftp01: Requesting service subsystem on channel 1.
sftp01: channel 1: open confirm rwindow 300000 rmax 30000
sftp01: sftp: Sending SSH2_FXP_INIT
sftp01: sftp: Remote version: 3
sftp01: sftp: Sent message T:11 I:0
Couldn't get handle: Failure at ./ line 47

I thought maybe I had to open the dir first so I tried putting this  
line in before the ls():


But I get a 'Couldn't get handle . . .' error on that line, too.

I've searched through the archives but there weren't very many  
responses to similar problems.  Any help would be appreciated.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About