#!/usr/bin/perl
use Net::FTP;
( $day, $mon, $year) = (localtime)[3..5];
$mon=$mon+1;
$year=$year+1900;
$host_ip=`ifconfig eth0 |grep "inet addr" |cut -d: -f2 |cut -d" " -f1`;
chomp($host_ip);
$localfile="$host_ip&$year$mon$day.txt";
$ftp=Net::FTP->new("host_ip", Debug=>1)
or die "Cannot connect to host_ip:$@";
$ftp->login("ftpname",'mima')
or die "Cannot login",$ftp->message;
$ftp->cwd("/var/ftp/pub")
or die "Cannot change working directory", $ftp->message;
$ftp->put ("$localfile")
or die die "put failed",$ftp->message;
$ftp-quit;
在十几号的时候写了上面那个脚本,发现到10号前,文件日期出了问题,悲催,因为我的python脚本的文件日志格式是20130105,上面的是201315,没办法用shell修改下吧
#!/usr/bin/perl
use Net::FTP;
$time=`date +%Y%m%d`;
chomp($time);
$host_ip=`ifconfig eth0 |grep "inet addr" |cut -d: -f2 |cut -d" " -f1`;
chomp($host_ip);
$localfile="$host_ip&$time.txt";
$ftp=Net::FTP->new("host_ip(ftp服务器IP)", Debug=>1)
or die "Cannot connect to host_ip:$@";
$ftp->login("用户",'密码')
or die "Cannot login",$ftp->message;
$ftp->cwd("/var/ftp/pub")
or die "Cannot change working directory", $ftp->message;
$ftp->put ("$localfile")
or die die "put failed",$ftp->message;
$ftp-quit;
本文转自 西索oO 51CTO博客,原文链接:http://blog.51cto.com/lansgg/1089463