Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Doing an 'ls' in SFTP:Foreign

by StarkRavingCalm (Sexton)
on Feb 20, 2013 at 18:36 UTC ( #1019821=note: print w/ replies, xml ) Need Help??


in reply to Re: Doing an 'ls' in SFTP:Foreign
in thread Doing an 'ls' in SFTP:Foreign

Ok, I am ALMOST there... I have the 'ls' going to a array and getting close to what I would expect. Currently, it is ignoring hidden files and giving filenames. What I need is to get the size of each file without all the atime, mtime, perms etc... that appears to be default in SFTP-Foreign.

NOTE: I am only using 'names_only' as a proof of concept in case that negates any file size arguments I would put in there.

Does anyone know how to get the file size as an argument in the string I am using?

my @newarray = @{ $sftp->ls('/home/ftptest/inbound', names_only => 1, +no_wanted => qr/^\./ )};


Comment on Re^2: Doing an 'ls' in SFTP:Foreign
Download Code
Re^3: Doing an 'ls' in SFTP:Foreign
by salva (Monsignor) on Feb 21, 2013 at 09:13 UTC
    Just loop over the returned values generating a new list with the fields you want to keep:
    my $ls = $sftp->ls('/home/ftptest/inbound', no_wanted => qr/^\./ ); my @names_and_sizes = map { { filename => $_->{filename}, size => $_-> +{a}->size } } @$ls; # or... my %size = map { $_->{filename} => $_->{a}->size } @$ls;

      Perfect!

      $VAR1 = { 'text.txt' => 0, '1.1' => 0, 'newfile' => 171, 'upfile1' => 0, 'newfile3' => 171, 'upfile2' => 0, 'upfile3' => 0, 'upfile4' => 312, 'slkdjslkd.lkjlsdfsdl' => 0, 'newfile2' => 171 };

      Thanks Salva!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-09-22 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls