Perl的FTP-----get文件

前端之家收集整理的这篇文章主要介绍了Perl的FTP-----get文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在Perl中,使用模块Net::FTP来使用FTP服务,

一般的使用步骤如下:

1. 使用Net::FTP的new方法来创建一个新的FTP对象。

2. 使用login方法登录到FTP服务器。

3. 使用cwd方法来切换目录。

4. 使用get方法获取文件

5. 使用put方法上传文件

6. 使用quit方法退出

下面是linux下perl编写的ftp程序连接非21端口的例子:

[root@localhost aa]# more connect_ftp.pl

#!/usr/bin/perl -wuse Net::FTP;

$server = '192.168.1.251';

$port = '9999';

$user = 'user';

$pw = '123456';

$ftp = Net::FTP->new($server,Port=>$port,Debug => 0,Timeout => 600) or die "Cannot connect./n";

$ftp->login($user,$pw) or die "Could not login./n";

$ftp->cwd('/opt/ftp/123') or die "Cannot change working directory./n";

$remotefile = '123456.mp3';

$localpath = '/usr/local/src';$localfile = $localpath . "/1234567890.mp3";

$ftp->get($remotefile,$localfile) or die "Could not get remotefile:$remotefile./n";

print "get file sucessful./n";

$ftp->quit;

 

执行一下看看:[root@localhost aa]# ./connect_ftp.pl get file sucessful.

猜你在找的Perl相关文章