使用 perl 从远程主机读取文件 [英] reading a file from remote host using perl

查看:42
本文介绍了使用 perl 从远程主机读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to read a file(temp.txt) placed under /root directory on remote host(ubuntu) in same LAN from ubuntu machine.(ssh and ftp are open) The perl script is able to connect and a OpenSSH dialog box appears asking for password and then program exists.Please anybody helps..below is my script.

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.

推荐答案

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

You must install sh open keys to be able to access X.X.X.X without a password.

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

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

Than you can try to access the host with ssh:

$ ssh X.X.X.X 

并添加类似的东西

local *FILE;

在文件的开头去掉这些关于裸字的警告.

at the beginning of the file to get rid of these warnings about bareword.

这篇关于使用 perl 从远程主机读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆