ftp

#!/usr/bin/perl
#function:            Copy a batch of files to another host by ftp at an specified time
#author:              atgc
#version:             1.0
#date of compilation  December 15,2003
#OS environment       Solaris, AIX & Red Hat Linux

#===================================step 1===================================>
#Define variables
#use strict;
#In the following 3 lines, you can change user name,password and the ip of remote host
$user="用户名";
$pass="密码";
$remotehost="192.168.1.1";

my(%opt,$Time_Start,$mytimes,$currentpath,@filelist,$transferstr);

#===================================step 2===================================>
#Get parameters
use Getopt::Std;
getopts("f:t:p:",/%opt);
if ((!defined $opt{p})||(!defined $opt{t}))
 {
  die "*****************************************************************************
  Function: Copy a batch of files to another host by ftp at an specified time
  Usage:    perl $0 -f specify a file -t time to transfer -p target path  &
  -f:       specify a file to be transferred(if not, transfer all files)
  -t:       time of transfer(the format should be 'hh:mm')
  -p:       target path
*****************************************************************************/n";
 }

#===================================step 3===================================>
#Transfer files by ftp
$mytimes=1;
while(1)
{
 $Time_Start = sub_format_datetime(localtime(time()));
 $Time_Start=~m/(/d{2}/:/d{2})/;
 if ($1 eq $opt{t})
 {
         if ($mytimes==1)
         {
   $currentpath=`pwd`;
   @filelist = (defined $opt{f}) ? $opt{f} : `ls $currentpath`;
   foreach $ele(@filelist)
   {
    chomp($ele);
    if ($ele=~m//.dmp$/i)
    {
     $dmp.="$ele ";
    }
    elsif ($ele=~m//.txt$/i)
    {
     $txt.="$ele ";
    }
   }
   $dmp = ($dmp ne '') ? "/nbinary/nmput $dmp" : '';
   $txt = ($txt ne '') ? "/nascii/nmput $txt"  : '';
   $transferstr="ftp -n $remotehost <<!/nuser $user $pass/ncd $opt{p}/nprompt$dmp$txt/nbye/n";
   if (($txt eq '') && ($dmp eq ''))
   {
    print "No files to be transferred in this directory./n";
   }
   else
   {
    system("$transferstr");
    print "Congratulations!, all files are transferred to remote host successfully./n";
   }
   exit;
         }
  $mytimes++;
 }
 else
 {
  $mytimes=1;
 }
}

#===================================step 4===================================>
#Get system time
sub sub_format_datetime
{
 local($sec, $min, $hour, $day, $mon, $year) = @_;
        sprintf("%4d-%02d-%02d %02d:%02d:%02d", $year+1900, $mon+1, $day, $hour, $min, $sec);
}
#===================================the end==================================> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值