文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Perl FTP的使用

Perl FTP的使用

时间:2010-04-14  来源:trt2008

在Perl中,使用模块Net::FTP来使用FTP服务,一般的使用步骤如下: 1. 使用Net::FTP的new方法来创建一个新的FTP对象。 2. 使用login方法登录到FTP服务器。 3. 使用cwd方法来切换目录。 4. 使用get方法来获取文件。 5. 使用put方法来上传文件。 6. 使用quit方法退出。 更多有关标准的Net::FTP模块的应用,可以参考PerlDoc里的说明:http://perldoc.perl.org/Net/FTP.html
[[email protected] Perl]# cat -n FTP.pl

1 #!/usr/bin/perl -w

2 #使用模块Net::FTP
3 use Net::FTP;
4 #创建新的FTP连接
5 $ftp = Net::FTP->new
6 (
7 "ftp.cpan.org",
8 Timeout => 30
9 ) or die "Could not connect.\n";
10 #登录用的用户名和密码
11 $username = 'anonymous';
12 $password = '[email protected]';
13 #登录到FTP服务器
14 $ftp->login($username,$password) or die "Could not login.\n";
15 #切换目录到/pub/CPAN
16 $ftp->cwd('/pub/CPAN');
17 #指定远程的文件和本地的文件
18 $remotefile = "CPAN.html";
19 $localfile = "CPAN.html";
20 #使用get方法下载远程文件到本地来
21 $ftp->get($remotefile,$localfile) or die "Could not get remotefile:$remotefile\n";
22 #退出FTP服务器
23 $ftp->quit;
[[email protected] Perl]# perl FTP.pl

[[email protected] Perl]# ls

CPAN.html FTP.pl rDNS.pl
[[email protected] Perl]# cat CPAN.html

<HTML>
<HEAD>
<TITLE>CPAN.html</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" TEXT="#000000">
... ... ...
</BODY>
</HTML>
相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载