#!/usr/bin/perl -w
use strict;
use LWP::Simple qw(get);
my $url = shift || "http://www.chinaunix.net";
my $content = get($url);
print $content;
exit 0;
获取网页
#!/usr/bin/perl
use strict;
use Net::FTP;
my $user = "anonymous";
my $passwd = "chinaunix@";
my $host = "ftp.freebsd.org";
my $ftp = Net::FTP->new("$host", Debug =>0)
or die "Can't connect to $host: $@\n";
$ftp->login("$user","$passwd")
or die "Can't login\n", $ftp->message;
$ftp->cwd("/pub/FreeBSD/doc/")
or die "Can't change dir\n", $ftp->message;
$ftp->get("README")
or die "get failed\n", $ftp->message;
$ftp->quit;
exit 0;
FTP下载
#!/usr/bin/perl
use Mail::Sender;
#my $mailtext = "Das is\'t der Text\nden ich gerne senden wuerde...";
my $sender = new Mail::Sender {
smtp => 'smtp.163.com',
from => 'zhuzhengju20@163.com',
auth => 'LOGIN',
authid => 'zhuzhengju20',
authpwd => '2000',
on_errors => undef,
} or die "Can't create the Mail::Sender object: $Mail::Sender::Error\n";
$sender->MailFile({to =>'hahazhu0634@126.com',
subject => 'Here is the file',
msg => "I'm sending you the list you wanted.",
file => './name.txt'}) or print $Mail::Sender::Error;
$sender ->Close();
发送带附件的邮件,需要验证,若不需要验证请参考下面的例子!~
[补充知识]
(1)安装Mail::Sender模组
perl -MCPAN -e shell
install Mail::Sender
(2)测试auth参数使用以下命令:
#perl -MMail::Sender -e "Mail::Sender->printAuthProtocols('smtp.sina.com.cn')"
#!/usr/bin/perl
use Mail::Sender;
open(IN, "< ./index.html") or die("");
$sender = new Mail::Sender{
smtp =>'localhost',
from =>'root@localhost'
};
$sender->Open({
to =>'zhuzhengju20@163.com',
subject =>'hello,baby!',
msg =>"please,recive content!",
ctype =>"text/html",
encoding =>"7bit",
});
while(<IN>)
{
$sender->SendEx($_);
}
close IN;
$sender->Close();
print $Mail::Sender::Error eq "" ? "send ok!\n" : $Mail::Sender::Error;
从本地发送HTML的邮件,不需要本地验证(若需验证,请参考上面的例子!~)
#!/usr/bin/perl
# fileName: predate
my %mon=(
1 =>"Jan", 2 =>"Feb", 3 =>"Mar", 4 =>"Apr",
5 =>"May", 6 =>"Jun", 7 =>"Jul", 8 =>"Aug",
9 =>"Sep", 10 =>"Oct", 11 =>"Nov", 12 =>"Dec"
);
my ($sec1,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time-86400);
$mon++;
$mon=$mon{$mon};
$mday = sprintf("%02s",$mday);
$hour = sprintf("%02s",$hour);
$min = sprintf("%02s",$min);
$sec = sprintf("%02s",$sec);
$year+=1900;
print "$mday/$mon/$year\n";
print "$hour:$min:$sec\n";
[注意:]
显示昨天的时间,如果将localtime(time-86400)改成localtime(time)那么时间就为今天的时间了