LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 612|回复: 4

ftp列表脚本

[复制链接]
发表于 2005-3-24 17:49:40 | 显示全部楼层 |阅读模式
#!/usr/bin/perl -w

use Net::FTP;
use strict;

my $server='ftp.xjtu.edu.cn';
my $user = 'ftp';
my $pw = 'ftp';


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;
}
发表于 2005-3-24 19:53:17 | 显示全部楼层
看不懂
5555555555
回复 支持 反对

使用道具 举报

发表于 2005-3-24 23:29:54 | 显示全部楼层
嘿,原来讨论组的是你啊,学习
回复 支持 反对

使用道具 举报

发表于 2005-3-25 20:48:16 | 显示全部楼层
Can't call method "login" on an undefined value at ./test line 12.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-3-26 12:57:11 | 显示全部楼层
你用的perl是什么版本的?
可能检查的太严格了
在login中把其他的参数都写上

这个脚本是递归列表ftp服务器的文件
可以用来作简易ftp搜索引擎
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表