使用perl从远程主机读取文件

时间:2012-06-21 09:47:24

标签: perl remote-file-inclusion

我正在尝试从ubuntu机器读取位于同一局域网中远程主机(ubuntu)上/ root目录下的文件(temp.txt)。(ssh和ftp是打开的) perl脚本能够连接并出现一个OpenSSH对话框,要求输入密码,然后程序就存在。请任何人帮忙。下面是我的脚本。

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.

1 个答案:

答案 0 :(得分:2)

您必须安装sh open键才能在没有密码的情况下访问X.X.X.X。

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

您可以尝试使用ssh访问主机:

$ ssh X.X.X.X 

请添加类似

的内容
local *FILE;

在文件的开头摆脱关于裸字的这些警告。

相关问题