- 论坛徽章:
- 0
|
本帖最后由 shuijingfei 于 2012-02-29 22:17 编辑
回复 2# dwm1235
#!/usr/bin/perl -w
use strict;
use warnings;
use Net::FTP;
my $config_file="/home/etlplus/ETLPLUS/script/kit/config_dat.txt";
open(CFG,$config_file ) || die "can't open config file !\n";
my ($ip1,$ip2,$ip3,$user,$passwd,$remote_dir,$dir);
$dir=$ARGV[0];
while (<CFG>)
{
if (/ip/){
$ip1=(split(/;/,(split(/=/,$_))[1]))[0];
$ip2=(split(/;/,(split(/=/,$_))[1]))[1];
$ip3=(split(/;/,(split(/=/,$_))[1]))[2];
} elsif (/username/){
$user=(split(/=/,$_))[1];
} elsif (/password/){
$passwd=(split(/=/,$_))[1];
} elsif (/task/){
$remote_dir=(split(/=/,$_))[1];
# $dir=(split(/;/,(split(/=/,$_))[1]))[1];
} else {
next;
}
}
chomp $passwd;
chomp $user;
chomp $ip1;
chomp $ip2;
chomp $ip3;
chomp $remote_dir;
chomp $dir;
close(CFG);
########################################
print $remote_dir."aaa\n" ;
预期应该是/dwetl/dsproc/rjtaaa,但实际输出aaaetl/dsproc/rjtaaa
########################################
#ip1
BLOCK1: {
my $ftp = Net::FTP->new("$ip1",Passive=>1) or die("Cant connect to " . $ip1);
my $msg = "\nconnect to host:".$ip1."\n";
print $msg;
$ftp->login($user,$passwd) or die("Cannot login in:",$ftp->message);
$msg = "\nlogin to host:".$ip1."\n";
print $msg;
$ftp->binary();
$ftp->cwd($remote_dir."/".$dir) or last BLOCK1 ;
my @remote_dat_files=$ftp->dir();#$ftp->ls与$ftp->dir结果不同,ls显示文件名列表,dir显示文件所有属性列表(文件名,大小,修改日期等)
my @FILES=grep(/\.dat$/i,@remote_dat_files);
foreach my $remote_dat_file (@FILES) {
my $size=(split(/\s+/,$remote_dat_file))[4];
chomp $size;
next if ($size eq "0") ;
my $name=(split(/\s+/,$remote_dat_file))[8];
chomp $name;
next if ($name=~m/Rjd_cbs_o_stkasset/);
# next if ($name=~m/^a\.dat$/);
# die("file_name:".$remote_dir."/".$dir."/".$name) ;
die("\nFailed!\n"."IP:".$ip1."file_name:".$remote_dir."/".$dir."/".$name."\n") ;
}
$ftp->quit();
}
|
|