从用perl远程主机读取文件(reading a file from remote host usi

2019-06-25 15:17发布

我想读取Ubuntu的机器在同一个局域网内远程主机(Ubuntu的)上/根目录下放置一个文件(TEMP.TXT)。(SSH和FTP是开放的)的Perl脚本是能够连接并出现OpenSSH的对话框询问密码,然后程序exists.Please人helps..below是我的脚本。

use POSIX qw(strftime);
use strict;
use warnings;


use File::Remote;
 my $remote = new File::Remote;

# Standard filehandles
$remote->open(FILE, ">>X.X.X.X:/root/temp.txt") or die $!;
print FILE "Here's a line that's added.\n";
$remote->close(FILE);

执行时,我得到下面的错误。

Bareword "FILE" not allowed while "strict subs" in use at /root/Desktop/test.pl line 10.
Bareword "FILE" not allowed while "strict subs" in use at /root/Desktop/test.pl line 12.
Execution of /root/Desktop/test.pl aborted due to compilation errors.

Answer 1:

您必须安装SH开启键可以不用密码来访问XXXX。

$ ssh-keygen
$ ssh-copy-id -i ~/.ssh/id_rsa.pub X.X.X.X

比你可以尝试用ssh来访问主机:

$ ssh X.X.X.X 

并加入请像

local *FILE;

在文件的开头来摆脱这些警告对裸字的。



文章来源: reading a file from remote host using perl