mantra2006 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

I know this is perl place but I am struck with this quite
some time. Hope somebody helps me in this
I have to connect to a site using sftp and downloading the
files after successfully downloading the files
the script will call perl program for further processing
The problem is after connecting to site am not able to get the list in an array
so that i can download files one by one
here is the script
sftp -oIdentityFile=keys/public_key -oPort=555 -oUser=anonymous -oHost +name=proxy-someserver.abcx.com $host << EOF lcd $file_dir cd $local_dir ls bye EOF When I run the above script it displays the list of files in the direc +tory...I want to get that list in a array and loop through it to down +load all the files so when I does this @files=`ls` echo $files it says invalid command...


Thanks in advance for the help

Sridhar

Replies are listed 'Best First'.
Re: SFTP in ksh
by zentara (Cardinal) on Aug 23, 2006 at 15:55 UTC
    Hi, you might want to consider using the SFTP functions in the Net::SSH2 module. Here is a simple example showing how to get a dirlst, and getting files.
    #!/usr/bin/perl use warnings; use strict; use Net::SSH2; # see maillist archives at # http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users my $ssh2 = Net::SSH2->new(); $ssh2->connect('localhost') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('z','ztester') or die "Unable to login $@ \n"; #$ssh2->auth_keyboard('root','*******'); my $sftp = $ssh2->sftp(); # get a dirlist (print or push into an array) my $dh = $sftp->opendir($dir); while(my $item = $dh->read) { print $item->{'name'},"\n"; } #get a file use IO::Scalar; my $check = IO::Scalar->new; # $remote can be from an array you got above $ssh2->scp_get($remote, $check); print "$check\n\n"; # of course you may want to open a filehandle and # actually save the file

    I'm not really a human, but I play one on earth. Cogito ergo sum a bum