您的位置:首页 > 编程语言 > PHP开发

获取ftp文件列表的perl程序

2010-07-09 16:41 417 查看
#!/usr/bin/perl -w
use Net::FTP;
use strict;
my $server='IP地址';
my $user = '用户名';
my $pw = '密码';

my $ftp = Net::FTP->new($server) ;

$ftp->login($user,$pw) or die "login failed!/n";
print "login ok! starting list files on $server..../n";

&list("/cmcc_cbbs/balance/zhangxr");

$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;
}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  perl list login server path user