Monday, 15 September 2014

perl ssh then read file on remote server -



perl ssh then read file on remote server -

i need

connect remote server; then do things, open , read contents of file.

for step 1:

my $server = "remoteservername.company.com"; $ssh = net::ssh::perl->new("$server", debug => 1, protocol => 2, stricthostkeychecking => "no") or die "error connecting server $server";

yields msg on terminal

connection established.

so presume ssh connected remote server, via code.

for step 2, how open , read file on remote server using code local server? best can far:

use strict; utilize warnings; utilize diagnostics; utilize warnings::register; utilize net::ssh::perl; utilize net::ssh::expect; utilize math::bigint lib => "calc,gmp,pari"; $server = "server09"; $ssh = net::ssh::perl->new("$server", debug => 1, protocol => 2, stricthostkeychecking => "no") or die "error connecting server $server"; #open(file, "/home/myid/f09.txt") || print("unable open test.o\n"); #works, on local, opens file[does not fail]. #open(file, "server09://home/myid/f09.txt") || print("unable open test.o\n"); #---> error: "unable open test.o" @remote_text = `this text set array.`; $remote_text = bring together ('',@remote_text); open (file,'>/home/myid/f09.txt'); print file "$remote_text"; close (file); exit(0);

yet, not add together existing file f09.txt; if delete file, open not create it. no errors, not seem contact remote file.

just simple explanation of ssh, read remote file helpful. other examples see aren't cutting it. of course, me, long day, gotta walk away while. time much appreciated!

you trying modify file exists on machine on ssh. file operations functions cannot handle that.

is possible download file other server, update on local , re-upload file?

you may want experiment ssh command:

my @remote_text = ('this text set array.'); $remote_text = bring together ('',@remote_text); @args = ("ssh server09", "echo '$remote_text' > /home/myid/f09.txt"); system(@args) == 0 or die "system @args failed: $?"

perl ssh

No comments:

Post a Comment