Hello slugger415,

Fellow Monks have provided you with multiple solutions. Just to add one more :):

#!/usr/bin/perl use strict; use warnings; use Net::SFTP; my $host = '127.0.0.1'; my %args = ( user => 'tinyos', ssh_args => [ port => "22" ] ); my $sftp = Net::SFTP->new($host, %args); my $ls = $sftp->ls('/home/user/Monks'); print "$_->{filename}\n" for (@$ls); __END__ $ perl test.pl benchmark.pl~ Foo sample.pl test.log out.txt sample.pl~ .. .. ..

Minor note to make here, I am not using password I use ssh keys, I think you should do the same is far far more safe.

Having said all that why not use Net::SFTP::Foreign? Why I should you use this module? Simply read here Net::SFTP::Foreign Vs. Net::SFTP Vs. Net::SSH2::SFTP.

Sample of code just as your example:

#!usr/bin/perl use strict; use warnings; use Net::SFTP::Foreign; my %args = ( host => "127.0.0.1", user => "user", port => "22", # psw => "psw", # uncomment if you are using passwords key_path => "/home/user/.ssh/id_rsa" ); # comment if you are +using passwords my $sftp = Net::SFTP::Foreign->new(%args); $sftp->die_on_error("Unable to establish SFTP connection"); my $ls = $sftp->ls('/home/user/Monks') or die "unable to retrieve directory: ".$sftp->error; print "$_->{filename}\n" for (@$ls); __END__ $ perl test.pl benchmark.pl~ Foo sample.pl test.log out.txt sample.pl~ .. .. ..

Both examples above are based on my local configurations, so simply update them based on your configurations.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Using Net::SFTP by thanos1983
in thread Using Net::SFTP by slugger415

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.