设为首页 加入收藏

TOP

获取ftp文件列表的perl程序
2014-11-23 20:01:22 】 浏览:308
Tags:获取 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;
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇简单的服务器端表单数据验证代码 下一篇常用数据库JDBC连接法

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目