Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Doing an 'ls' in SFTP:Foreign

by salva (Abbot)
on Feb 15, 2013 at 16:19 UTC ( #1018904=note: print w/replies, xml ) Need Help??

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

ls returns an array reference:
$l = $sftp->ls(...) or die "ls failed: ".$sftp->error; for my $e (@$l) { ... }

Replies are listed 'Best First'.
Re^2: Doing an 'ls' in SFTP:Foreign
by StarkRavingCalm (Sexton) on Feb 15, 2013 at 17:28 UTC

    Why does this work flawlessly in Net:SFTP but not Net:SFTP:Foreign?

      I haven't used these packages, but the man page for Net::SFTP says ls returns a list of entries, while Net::SFTP::Foreign says it returns a reference to a list of entries.


        Maybe Salvo knows how to format the line to work with Foreign?

      Different modules, different APIs.

      Retrospectively, having ls return an array reference, was probably a bad idea, bad it is too late to change it now.

        What do you suggest to achieve the same results?
      It works flawlessly in both libraries. It just works differently.
Re^2: Doing an 'ls' in SFTP:Foreign
by StarkRavingCalm (Sexton) on Feb 15, 2013 at 20:36 UTC

    Maybe salva knows how to format that line to work with Foreign?

Re^2: Doing an 'ls' in SFTP:Foreign
by StarkRavingCalm (Sexton) on Feb 20, 2013 at 18:36 UTC

    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/^\./ )};
      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;


        $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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1018904]
[Corion]: :-D
[Corion]: I think that ITIL is mostly to prevent people from doing harm to a system that basically runs unattended :)
[Corion]: Maybe you could reduce ITIL to a computer network, a man and a dog. The network runs the computations. The man is there to feed the dog. The dog is there to prevent the man from accessing the computers.
[marto]: from experience of this side of the fence, it's all about proving to people that you are ITIL compliant, then the client ignores logical processes anyway :P
[marto]: when you work on the outside, for a client, you can make them aware of the stupids, but they don' t always listen :/
[Corion]: Yeah, you can lead them to water, but it's illegal to drown them...
[Discipulus]: Here my solution marto: create a win fake machine insied AD. do a micro fake partition foreach remote partition you wont to monit. put a web server that acept from data from remote systems and full fake partition as needed. fake partition are Mb. ;=)

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2017-01-24 10:35 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (203 votes). Check out past polls.