title: perl ssh then read file on remote server
body: <p>I need to </p>
  
  <ol>
  <li>connect to a remote server; then</li>
  <li>do some things, like open and read the contents of a file.</li>
  </ol>
  
  <p>For step 1:</p>
  
  <pre><code>my $server = "remoteservername.company.com";
  my $ssh = Net::SSH::Perl-&gt;new("$server", debug =&gt; 1, protocol =&gt; 2, StrictHostKeyChecking =&gt; "no") or die "Error connecting server $server";
  </code></pre>
  
  <p>yields msg on terminal</p>
  
  <blockquote>
    <p><code>Connection established.</code></p>
  </blockquote>
  
  <p>so I presume I am ssh connected to remote server, via the code.</p>
  
  <p>For step 2, how do i open and read a file on the remote server using code from the local server? this is the best i can do so far:    </p>
  
  <pre><code>use strict;
  use warnings;
  use diagnostics;
  use warnings::register;
  use Net::SSH::Perl;
  use Net::SSH::Expect;
  use Math::BigInt lib =&gt; "Calc,GMP,Pari";
  
  my $server = "server09";
  my $ssh = Net::SSH::Perl-&gt;new("$server", debug =&gt; 1, protocol =&gt; 2, StrictHostKeyChecking =&gt; "no") or die "Error connecting server $server";
  
  #open(FILE, "/home/myid/f09.txt") || print("Unable to open test.o\n"); #works, on local, opens file[does not fail].
  
  #open(FILE, "server09://home/myid/f09.txt") || print("Unable to open test.o\n");  #---&gt; error: "Unable to open test.o"
  
  my @remote_text = `this text is put into array.`;
  my $remote_text = join ('',@remote_text);
  open (FILE,'&gt;/home/myid/f09.txt');
  print FILE "$remote_text";
  close (FILE);
  
  exit(0);
  </code></pre>
  
  <p>yet, it does not add anything to existing file <code>f09.txt</code>; also if i delete the file, the <code>open</code> does not create it. no errors, but this does not seem to contact the remote file.</p>
  
  <p>just a simple explanation of ssh, then read from remote file would be helpful. other examples i see aren't cutting it. of course, could be me, long day, gotta walk away from it for a while. your time is very much appreciated!</p>