• Net::FTP::Recursive 递归FTP调用


    语法:

        use Net::FTP::Recursive;
    
        $ftp = Net::FTP::Recursive->new("some.host.name", Debug => 0);
        $ftp->login("anonymous",'me@here.there');
        $ftp->cwd('/pub');
        $ftp->rget( ParseSub => \&yoursub );
        $ftp->quit;

    说明:

    默认缺省采用 UNIX-style directory listings 列表方式处理。如果ftp是其他方式的列表,要自己提供方法解析数据,返回一个 Net::FTP::Recursive::File objects 列表。
    当Debug 设置为1,ftp将打印命令到STDERR。
    所以方法如果执行成功返回 false ‘’,true值为失败。

    构造函数:

    new (HOST [,OPTIONS])
    参照Net::FTP  的new 方法。

    方法:

    rget ( [ParseSub =>\&yoursub] [,FlattenTree => 1] [,RemoveRemoteFiles => 1] )

    rput ( [FlattenTree => 1] [,RemoveLocalFiles => 1] )

    rdir ( Filehandle => $fh [, FilenameOnly => 1 [, PrintType => 1] ] [, ParseSub => \&yoursub ] )

    rdelete ( [ ParseSub => \&yoursub ] )

    Net::FTP::Recursive::File 辅助类

    # Parsing subroutine for Windows
    # - may also be used as an example for your own FTP server if your output
    #   isn't parsing correctly
    
    
    sub parse_sub{
    
        my(@to_return) = ();
    
        foreach my $line (@_) {
    
            my($file); #reinitialize var
    
            next unless my @fields =
              $line =~ /^
                         (\S+)\s+ #date
                         (\S+)\s+ #time
                         (<DIR>)?\s* #user owner %u
                         (\d+)\s+ #size %s
                         (.+?)\s* #filename %f
                         (?:->\s*(.+))? #optional link part %l
                        $
                       /x;
    
    
            @fields = ( $fields[2], undef, undef, undef, $fields[3],
                        "$fields[0]$fields[1]", @fields[4,5] );
    
            my($perms) = ($fields[0]);
    
            next if $fields[6] =~ /^\.{1,2}$/;
    
            if ($perms =~ /<DIR>/){
                $file = Net::FTP::Recursive::File->new(IsPlainFile => 0,
                                                       IsDirectory => 1,
                                                       IsSymlink   => 0,
                                                       OriginalLine => $line,
                                                       Fields => [@fields]);
            }
            else {
                $file = Net::FTP::Recursive::File->new(IsDirectory => 0,
                                                       IsPlainFile => 1,
                                                       IsSymlink   => 0,
                                                       OriginalLine => $line,
                                                       Fields => [@fields]);
            }
    
            push(@to_return, $file);
        }
    
        return(@to_return);
    }
    # linux 方式的ftp命令解析
     $line =~ /^([a-z-])([a-z-]{9})  # -rw-r--r--
                          \s+(\d*)                # 1
                          (?:\s+(\w+))(?:\s+(\w+))         # root root
                          \s+(\d+)                # 312
                          \s+(\w+\s+\d+\s+[\d:]+) # Aug 1 1994
                           \s+(.+)               # welcome.msg
        
                     $/x;
  • 相关阅读:
    python命令行工具模块-click
    python项目代码打包成Docker镜像
    背包九讲
    秒杀项目的3个奇数问题:并发队列的选择,请求接口的合理设计,高并发下的数据安全
    java类加载过程
    索引失效
    java面试
    进程间通信
    HashMap在Jdk1.7和1.8中的实现
    十大排序算法
  • 原文地址:https://www.cnblogs.com/tjxwg/p/2914753.html
Copyright © 2020-2023  润新知