Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Ok, it's been a while since I've been this stumped on a Perl question and resorted to asking for help.

Ultimately, what I'm trying to accomplish here is to get information on any given remote file. I have access to the remote system via ssh and know the file's full path: call that $remotefile

The approach I was thinking of using is like so:

use Net::SSH::Perl; my $ssh = Net::SSH::Perl->new($remotehost); $ssh->login($remoteuser, $remotepassword); my($stdout, $stderr, $exit) = $ssh->cmd(qq[ls -l $remotefile]); # Then parse the info I want from $stdout with an easy regex

But I can't rule out the possibility that the remote filename might contain shell metacharacters.

My immediate thought was, "No problem, I'm sure the CPAN has six different modules for escaping shell metacharacters," but all I seem to be able to find is modules that appear to be intended for escaping strings in program source code (notably, String::Escape) or undoing said escaping (Encode::Escape for instance). To the best of my knowledge, those probably won't do entirely the right thing (e.g., with spaces). Am I correct in assuming that I need something different?

The characteristics of the remote system are known, and are essentially the same as the local system, although they get updates at different times. (Both systems are Debian.)

Thoughts? Other approaches?

We're working on a multi-year set of freely redistributable Vacation Bible School materials.

In reply to Getting information about a remote file via SSH: how to escape the filename by jonadab

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (2)
    As of 2021-03-05 05:05 GMT
    Find Nodes?
      Voting Booth?
      My favorite kind of desktop background is:

      Results (109 votes). Check out past polls.