Hi I'm very new to perl and would really appreciate some help.I have a script which transfers files to multiple remote hosts, without having to enter passwords. In my script the user can pass two arguments. The first argument is the directory or file test.txt in this example below. The second argument is the location on the remote hosts where I'd like the file to be placed. example: perl distributor.pl /home/user/testdir/test.txt /home/user/testdir/remotelocation/
#I have a hash for all the remote hosts my $remotehosts = { "78.example.com" => { user => 'user', host => '0.0.0.78', } "79.example.com" => { user => 'user', host => '0.0.0.79', } } $path = $ARGV[0]; $destination = $ARGV[1]; #the copy scp statement is in a while loop which loops through the key +s in the hash. $scp->scp($path, $remote->{user}.'@'.$remote->{host}.":".$destination)
At the moment when the user enters the location they would like to place the file. If the location doesn't exist a file will still be created. for example: perl distributor.pl /home/user/testdir/test.txt /home/user/test in the second argument if test directory doesn't exist on one of the remote host a file called test will be created. Is there a away to stop this from happening and inform the user that the directory they have typed doesn't exist? Thank you

In reply to Can you use Net::SCP to check if a remote dir exist before copying? by ibra

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.