这是一个关于Net::FTP模块的一个小小的基本程序,如想得到更多关于此模块的信息
请参考链接:http://perldoc.perl.org/Net/FTP.html
#! /usr/bin/perl
use Net::FTP;
#specific
$host="192.168.111.129";
#连接
my $ftp=Net::FTP->new($host) or die "can't connect to host:$host\n";
#登录
if(!$ftp->login("<user>","<password>"))
{
die "can't login into the host:$!\n";
}
#进入目录
if(!$ftp->cwd("/home/cheney/perl/script/"))
{
die "can't change to directory!\n";
}
#得到当前目录名
$current_dir=$ftp->pwd();
print "current dir is :$current_dir\n";
#得到当前目录下所有文件列表
@filelist = $ftp->ls($current_dir);
#得到当前目录下所有文件信息列表,信息比ls丰富,可得到文件权限等信息
@dirlist = $ftp->dir();
print "The file of current dir are:@filelist\n";
print "The current dir has below dirs:@dirlist\n";
#创建目录
$newdir=$ftp->mkdir("newdir/newdir",true);
print "you created a new dir:$newdir\n";
#下载文件
if(!$ftp->get("searchdir.pl"))
{
die "can't get file\n";
}
#上传文件
if(!$ftp->put("
test.pl"))
{
die "can't put file\n";
}
#重命名文件
if(!$ftp->rename("test.pl","test"))
{
die "can't rename file\n";
}
#退出连接
$ftp->quit or die "error occurs during quiting\n";