2012-06-21 31 views
1

我試圖讀取位於遠程主機(ubuntu)上的/ root目錄下的文件(temp.txt),它位於同一個局域網中(ssh和ftp打開) The perl腳本能夠連接並出現一個OpenSSH對話框,詢問密碼,然後程序exists.Please任何人都可以幫助..下面是我的腳本。使用perl從遠程主機讀取文件

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. 

回答

2

您必須安裝sh open keys才能訪問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; 

擺脫這些警告一下裸字。