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;