Board logo

标题: 获取ftp文件列表的perl程序 [打印本页]

作者: yuyang911220    时间: 2017-2-24 10:43     标题: 获取ftp文件列表的perl程序

获取ftp文件列表的perl程序


#!/usr/bin/perl -w
use Net::FTP;
use strict;
my $server='*.*.*.*';
my $user = 'anonymous';
my $pw = 'ftpuser';
my $ftp = Net::FTP->new($server) ;
$ftp->login($user,$pw) ;
print "login ok! starting list files on $server....\n";
&list("/");
$ftp->quit;

#*************************************************#
sub list()
{
my $current = $_[0];
my @subdirs;

$ftp->cwd($current);
my @allfiles = $ftp->ls();

foreach (@allfiles){
  if(&find_type($_) eq "d"){
   push @subdirs,$_;
  }
  else{
   print $current."/$_\n";
  }
}

foreach (@subdirs){
  &list($current . "/" . $_);
}
}
sub find_type{
my $path = shift;
my $pwd = $ftp->pwd;
my $type = '-';
if ($ftp->cwd($path)) {
  $ftp->cwd ($pwd);
  $type = 'd';
}
return $type;
}




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0