- 连接到远程服务器;然后
- 做一些事情,比如打开并读取文件的内容。
对于步骤1:
my $server = "remoteservername.company.com";
my $ssh = Net::SSH::Perl->new("$server", debug => 1, protocol => 2, StrictHostKeyChecking => "no") or die "Error connecting server $server";
产生上终端
Connection established.
所以我相信我的ssh连接到远程服务器味精,通过该代码。
对于第2步,如何使用本地服务器的代码打开并读取远程服务器上的文件?这是最好的,我可以到目前为止做:
use strict;
use warnings;
use diagnostics;
use warnings::register;
use Net::SSH::Perl;
use Net::SSH::Expect;
use Math::BigInt lib => "Calc,GMP,Pari";
my $server = "server09";
my $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 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"); #---> error: "Unable to open test.o"
my @remote_text = `this text is put into array.`;
my $remote_text = join ('',@remote_text);
open (FILE,'>/home/myid/f09.txt');
print FILE "$remote_text";
close (FILE);
exit(0);
的是,它并不以现有文件f09.txt
添加任何东西;另外如果我删除文件,open
不会创建它。没有错误,但这似乎没有联系远程文件。
只是对ssh的一个简单的解释,然后从远程文件中读取会有所帮助。我看到的其他例子并没有削减它。当然,可能是我,漫长的一天,得离开它一段时间。你的时间非常感谢!
如果我是你,我会写Perl脚本来完成本地任何事情并通过ssh执行它。 – reinierpost 2014-10-10 10:18:40