现在的位置: 首页 > 综合 > 正文

perl脚本:FTP获得服务器文件

2017年10月26日 ⁄ 综合 ⁄ 共 767字 ⁄ 字号 评论关闭

该脚本采用FTP方式从批量服务器上获得文件。

#!perl
#Author: HC
#Date: 2012/10/22

use Net::FTP;
use Cwd;

$localFile = getcwd()."/log/";

if (!-e $localFile){
	mkdir $localFile, 0755 or warn "Cannot make $localFile directorty:$!";
}

if (!open SERVER_INFO, getcwd()."/ftpserver.txt"){
	die "Ftp server information file can not be found:$!";
}

while (<SERVER_INFO>){
	@fields = split;
	$serverName = $fields[0];
	$server = $fields[1];
	$port = $fields[2];
	$user = $fields[3];
	$pwd  = $fields[4];
	$remoteFile = $fields[5];
	
	$ftp = Net::FTP->new($server, Port=>$port, Debug=>0, Timeout=>1000)
		or die "Cannot connect:$!";
	$ftp->login($user, $pwd)
		or die "Could not login:$!";
	$ftp->get($remoteFile, $localFile.$serverName.".log")
		or die "Could not get remote file:$remoteFile:$!";
	print $serverName."Get file successful.\n";
	$ftp->quit;
}

print "Press <Enter> to continue...";
<>;

system "start $localFile";

抱歉!评论已关闭.