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:

#!/usr/bin/perl

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

my $gpg_homedir = "/home/fnbosftp/.gnupg";
my $host = `/etc/db_auth fnbo hostname`;
chomp($host);
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
get_files($pickup_dir,$host);

sub get_files
{
        my ($pickup_dir,$host) = @_;
        my $username = `/etc/db_auth fnbo username`;
        my $password = `/etc/db_auth fnbo password`;
        chomp($host,$username,$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: $! \n";
        print FH localtime(). " $message\n";
        close(FH);
}

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 sftp.1st.com, port 22.
sftp01: Remote protocol version 2.0, remote software version 0
sftp01: Net::SSH::Perl Version 1.34, protocol version 2.0.
.sftp01.overstock.com: 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 'sftp.1stsignal.com' 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 ./sftp_get.pl line 47

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

$sftp->do_opendir("$pickup_dir");

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.

Matt

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to