perl 模块学习之Net::FTP

上一篇 / 下一篇  2011-05-16 14:34:29 / 个人分类:Script Language

这是一个关于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";




TAG:

 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 5444
  • 日志数: 7
  • 建立时间: 2010-11-21
  • 更新时间: 2011-05-16

RSS订阅

Open Toolbar