+ -
当前位置:首页 → 问答吧 → Perl FTP上循环下载文件调用Oracle处理文件中的疑惑

Perl FTP上循环下载文件调用Oracle处理文件中的疑惑

时间:2010-11-10

来源:互联网

程序实现:
【前提】FTP上有若干个文本文件
【目的】一直循环处理:先从ftp上下载一个文件,然后调用Oracle处理文本文件中的内容,现在

目前只能下载一个文件调用Oracle处理,在下载第二个文件的时候文件就一直没有down下来,强制终止的时候出现ftp超时提示,对于Perl是个菜鸟,从未接触过,原程序是从Linux上移植到Windows上来的
下附ftp下载过程的代码

this_file=$filename;
print "this file is $this_file\n";

$next_file=next_file_name($this_file);
print "next file is $next_file\n";

$ftp = Net::FTP->new($aaa_server_ip, Debug => 0) or die "Cannot connect to some.host.name: $@";
print "11111111111111111111111\n";
$ftp->login($ftp_user,$ftp_passwd) or die "Cannot login ", $ftp->message;
$ftp->cwd($remote_dictionary) or die "Cannot change working directory ", $ftp->message;

@file_list=$ftp->ls("$next_file");
print @ftp_list;


也就是说在下第二个文件的时候“1111111”是打印不出来的,而且一直是死等,调用获取的文件名都是正确的
请教老鸟简洁说明下,万分感谢(PS 高深的看不懂,对于Perl从了目前的脚本里的东西之外基本一无所知)

作者: xiaobao929   发布时间: 2010-11-10

你这个脚本会循环去调用Net::FTP->new建立新的FTP连接吗?如果是,第二次调用的时候FTP连接有没有关闭?FTP服务器有没有连接数的限制?你能不能换一个FTP试验下同样的代码看看能不能运行?如果FTP服务器是自己建的,可以通过一下FTP的管理接口或者日志诊断下问题。
如果你把代码再简化补全下,简化补全成可以独立执行的一段脚本(当然,这段脚本要能反映出你的问题),其他人或许可以帮你实际运行下看看。

作者: iambic   发布时间: 2010-11-10

每次获取完成后都会调用$ftp->quit;
第二次调用的时候根本就没有连接上FTP服务器
FTP服务器应该没有连接数的限制,而且此服务器只有我一个人使用并且是我自己搭建的
不能换另一个FTP试验(换了和没换没什么区别,FTP就是我本地的机器,跑脚本的是公司的服务器,而且只有我的机器能连上)


抽出来的函数

sub get_ftp_file { 

$ftp_server_ip=$_[0]; 

$ftp_user=$_[1];

$ftp_passwd=$_[2];
$remote_dictionary=$_[3];
print "remote $remote_dictionary \n";
$local_dictionary=$_[4];
$filename=$_[5];
print "filename----- $filename";
$aaa_server_ip;
$aaa_name=$aaa_server_ip;
$aaa_name=~ s/\./_/g;
$control_filename=$aaa_name.".control";

print "\n****** $local_dictionary ****\n";
#chdir ;
##chdir $local_dictionary;
print $!;

$this_file=$filename;
print "this file is $this_file\n";

$next_file=next_file_name($this_file);
print "next file is $next_file\n";

$ftp = Net::FTP->new($ftp_server_ip, Debug => 0) or die "Cannot connect to some.host.name: $@";
print "11111111111111111111111\n";
$ftp->login($ftp_user,$ftp_passwd) or die "Cannot login ", $ftp->message;

$ftp->cwd($remote_dictionary) or die "Cannot change working directory ", $ftp->message;

@file_list=$ftp->ls("$next_file");
print @ftp_list;

#at least one file
if( $#file_list==0)
{


print "exist file : $file_list[0] \n";
print "this_file $this_file \n";
#$ftp->get($this_file) or print $ftp->message;
$ftp->get($this_file) or die "get failed", $ftp->message;
$ftp->quit;

if (-e $this_file )
{
print "### got $this_file success ! \n";
print "### load to oracle $this_file,$control_filename,$ftp_name \n";  
load_into_oracle($this_file,$control_filename,$ftp_name);
print "### load into oracle OK !";
return 1; 
}else
{
print "### cannot get $this_file this time \n";
return 0; 
}
}
else
{
print "\n### $next_file not exist \n";
print "### cannot get $this_file this time \n";
$ftp->quit;
return 0; 
}

}

作者: xiaobao929   发布时间: 2010-11-10

ftp_server_ip 要改成 $aaa_server_ip
不好意思

作者: xiaobao929   发布时间: 2010-11-10