Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trouble with a hash reference

Status
Not open for further replies.

cb49747

MIS
Apr 23, 2002
181
US
I'm trying to write a simple fetch program to get some files from a sftp server.

Here is what I got.

Code:
 $args{debug} = "true"; $args{user} = $ftp_user; $args{password} = $ftp_pass;

   $sftp = Net::SFTP->new($ftp_site, %args) or die "Cannot connect to $ftp_site: $@";
   @files = $sftp->ls($remote); 

foreach $f(@files) { 
 print $f;
   }

This should print out a list of the files on the sftp serverm, however it only prints out these hash refrences.

This is what I found a cpan.org

Code:
$sftp->ls($remote [, $subref ])
Fetches a directory listing of $remote.

If $subref is specified, for each entry in the directory, $subref will be called and given a reference to a hash with three keys: filename, the name of the entry in the directory listing; longname, an entry in a "long" listing like ls -l; and a, a Net::SFTP::Attributes object, which contains the file attributes of the entry (atime, mtime, permissions, etc.).

If $subref is not specified, returns a list of directory entries, each of which is a reference to a hash as described in the previous paragraph.

However, I not really sure what the above means. As I'm still learning here.

So, how would I turn these hash refrences into the actual file names?

Thanks for any help.
 
Ok,

I have done some reading on hashes and figured out that the associated array containg the file name would be put into $subref.

My question is how do i access that array? What is $subref tied to?

I would appreciate any help here.
 
ok I think I figured it out.

here is what I did.

Code:
   $sftp = Net::SFTP->new($ftp_site, %args) or die "Cannot connect to $ftp_site: $@";
   @files = $sftp->ls($remote); 

foreach $f(@files) { 
    $filename = $f->{'filename'};
    $file_list .= "$filename";
   }

close($sftp->{ssh}->sock());

This returned a list of the file names.
 
or a little more succintly:

Code:
foreach $f (@files) {
    $file_list .= $f->{'filename'};
}


- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top