#!/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语言编写的脚本,该脚本可以登录到指定的FTP服务器,并递归地列出服务器上特定目录内的所有子目录及文件。通过这个脚本,用户能够方便地获取远程FTP服务器上的文件结构。
2103

被折叠的 条评论
为什么被折叠?



