
package MYFTP;use Net::FTP;sub new{my $class = shift;#一个空的引用my $ref = {};#将引用和对象绑定bless($ref,$class);#返回引用return $ref;}#FTP下载文件sub DownLoadFtpfile{my $ref = shift;my $FtpServer = shift;my $Ftpport = shift;my $Ftpuser = shift;my $FtpPassWord = shift;my $FtpLocalSavePath = shift;my $FtpRemotePath = shift;my @FtpDownloadfile = @_;print "\nFtp 正在建立连接 IP:$FtpServer 端口:$Ftpport 用户名:$Ftpuser 密码:$FtpPassWord \n";my $ftp = Net::FTP->new($FtpServer,Port=>$Ftpport,DeBUG => 0,Timeout => 600) or dIE "Cannot connect.\n";print "\n连接成功,开始登陆.......\n";$ftp->login($Ftpuser,$FtpPassWord) or dIE "Could not login.\n";print "\n登陆成功,开始下载文件.......\n";$ftp->cwd($FtpRemotePath) or dIE "Cannot change working directory.\n";#文件全部下载成功退出死循环while(@FtpDownloadfile){my $Index = 0;my $ArraySize = @FtpDownloadfile;foreach my $file (@FtpDownloadfile){my $FtpDownLocalSavePath = $FtpLocalSavePath . "/$file";my $Return = $ftp->get($file,$FtpDownLocalSavePath);if($Return eq undef){print "\n下载$file文件失败\n";next;}print "\n下载$file文件成功\n";delete $FtpDownloadfile[$Index];$Index++;}}print"\n全部下载成功.......\n";$ftp->quit;}#FTP上传载文件sub UpLoadFtpfile{my $ref = shift;my $FtpServer = shift;my $Ftpport = shift;my $Ftpuser = shift;my $FtpPassWord = shift;my $FtpRemotePath = shift;my @FtpUploadfile = @_;print "\nFtp 正在建立连接 IP:$FtpServer 端口:$Ftpport 用户名:$Ftpuser 密码:$FtpPassWord \n";my $ftp = Net::FTP->new($FtpServer,开始上传文件.......\n";$ftp->cwd($FtpRemotePath) or dIE "Cannot change working directory.\n";#文件全部下载成功退出死循环while(@FtpUploadfile){my $Index = 0;foreach my $file (@FtpUploadfile){my $Return = $ftp->put($file);if($Return eq undef){print "\n上传$file文件失败\n";next;}print "\n上传$file文件成功\n";delete $FtpUploadfile[$Index];$Index++;}}print"\n全部上传成功.......\n";$ftp->quit;}#模块结束标识1;
use MYFTP;my $server = "10.92.209.156";my $port = "21";my $user = "root";my $pw = "root";my $LocalSavePath = "E:/11111/Test";my $RemotePath = "/home/songbaisen";my @Downloadfile;push @Downloadfile,"hell.pl";push @Downloadfile,"CELL0.csv";my $Ftp = MYFTP->new();#&DownLoadFtpfile($server,$port,$user,$pw,$LocalSavePath,$RemotePath,@Downloadfile);$Ftp->UpLoadFtpfile($server,@Downloadfile);总结
以上是内存溢出为你收集整理的PERL FTP模块全部内容,希望文章能够帮你解决PERL FTP模块所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)