免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2125 | 回复: 6
打印 上一主题 下一主题

ftp的fork下载不可以.帮忙看看哪里问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-22 08:20 |只看该作者 |倒序浏览
#!/usr/bin/perl

use Net::FTP;
sub ftpdown {
my $user="root";
my $passwd="ftpdown";
my $dates=`date '+%Y%m%d'`;
my $date=$dates-1;
#exec("mkdir -p /file/$date";

my $dirs="/file/$date";
my $haom="192.168";
my $wav=" ->";
my $xxx="xxx";
my $ftp=Net::FTP->new("@_",Port=>21) or die "can't connet@\n";
$ftp->login("$user","$passwd")or die"no login\n";
$ftp->binary;
$ftp->cwd("$dirs")or die "$@\n";
my @filelist=$ftp->dir();
foreach (@filelist){
if ($_ =~ l){
my $start=index($_,$haom);
my $starts=substr($_,$start);
my $ends=index($starts,$wav);
my $localfile=substr($starts,0,$ends);
my $downs=rindex($_,$haom);
my $remotefile=substr($_,$downs);
$ftp->get("$remotefile","$localpath/$localfile");
my $a="list";
print "$a\n";
}
if (!($_ =~ $xxx)){
my $downs=rindex($_,$haom);
my $remotefile=substr($_,$downs);
my $localfile=$remotefile;
$ftp->get("$remotefile","$localpath/$localfile");
}
#print "$_\n",foreach @filelist;

$ftp->quit;
}
}
my @host=("192.168.0.221","192.168.0.224","192.168.0.225","192.168.0.227");
my %pid_to_host;
my $dates=`date '+%Y%m%d'`;
my $date=$dates-1;
if (!(-e "/file/$date")){exec("mkdir -p /file/$date");}
foreach (@host){
if (my $pid=fork){
$pid_to_host{$pid}=$_;
}else{
exit !ftpdown($_);
}
}
while(keys %pid_to_host){
my $pid=wait;
last if $pid <0;
my $host=delete $pid_to_host{$pid},next;
#print "ftp download file is securell\n";

}



各位帮忙看下,为什么这段代码不能下载.如果改成列出@filelist的条目都可以显示!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2008-01-22 16:21 |只看该作者
没有错误讯息???

论坛徽章:
0
3 [报告]
发表于 2008-01-23 10:29 |只看该作者
什么错误信息都没有!

论坛徽章:
0
4 [报告]
发表于 2008-01-23 10:39 |只看该作者

  1. if ($_ =~ l){
  2. my $start=index($_,$haom);
  3. my $starts=substr($_,$start);
  4. my $ends=index($starts,$wav);
  5. my $localfile=substr($starts,0,$ends);
  6. my $downs=rindex($_,$haom);
  7. my $remotefile=substr($_,$downs);
  8. $ftp->get("$remotefile","$localpath/$localfile");
  9. my $a="list";
  10. print "$a\n";
  11. }
  12. if (!($_ =~ $xxx)){
  13. my $downs=rindex($_,$haom);
  14. my $remotefile=substr($_,$downs);
  15. my $localfile=$remotefile;
  16. $ftp->get("$remotefile","$localpath/$localfile");
  17. }
复制代码

先保证这两个匹配是不是成功吧,是不是能打印点信息出来看下。
最起码 print "$a\n"; 这句打印出来没有。

论坛徽章:
0
5 [报告]
发表于 2008-01-23 10:43 |只看该作者
我能打印出$remotefile ,跟$localfile还有$a都可以打印出来.
在本机器上下载不回来文件!其它的变量都可以打印出来!

论坛徽章:
0
6 [报告]
发表于 2008-01-23 10:49 |只看该作者
192.168.0.224_6765_057487423130_078_20080122094436.wav 192.168.0.224_6765_xxx_078_20080122094436.wav
192.168.0.224_6765_057582188880_078_20080122105750.wav 192.168.0.224_6765_xxx_078_20080122105750.wav
192.168.0.224_6765_057768685444_078_20080122100840.wav 192.168.0.224_6765_xxx_078_20080122100840.wav
192.168.0.224_6765_057768685444_078_20080122101049.wav 192.168.0.224_6765_xxx_078_20080122101049.wav
这个是打印部分($remotefile跟$localfile)
但就是没有看到文件下载回来!

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
7 [报告]
发表于 2008-01-24 17:52 |只看该作者
$localpath/$localfile 这个目录你有权限吗?
$ftp->get("$remotefile","$localpath/$localfile");
後面加个
|| die "$@";
可能会出现Error message..
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP