免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2320 | 回复: 7
打印 上一主题 下一主题

请问用perl如何实现在虚拟主机上定时取文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-01 21:34 |只看该作者 |倒序浏览
我想到其他网站仅仅取得一个文件。 放在我自己的网站。
每天更新的。谢谢
不过我的网站建在虚拟主机上. 基本配置是无法改变的.

论坛徽章:
0
2 [报告]
发表于 2006-01-01 21:42 |只看该作者
看看有没有 LWP 模块。用这模块来获取其他网站的文件。
use LWP::Simple;
getstore($url, $file);

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
3 [报告]
发表于 2006-01-02 08:18 |只看该作者
可以用crontab 吗? 如果可以写个简单的shell script或perl script..配合crontab 就行了..
不然..找第三台机器,可以使用crontab的...把file从A抓下来,再ftp到B....

论坛徽章:
0
4 [报告]
发表于 2006-01-05 20:44 |只看该作者
不能用crontab.  而且我这里不能用ftp的.

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
5 [报告]
发表于 2006-01-06 08:22 |只看该作者
可以用CGI吗? 如果可以的话..写个upload的cgi...再自己找台可以用LWP的机器,传上去....

论坛徽章:
0
6 [报告]
发表于 2006-01-09 19:11 |只看该作者
谢谢. 能不能说得再具体一点.  就是说server和client如何通信?
主机上要有一个upload.cgi 我再写有个client.pl  , 他们如何接头?

多谢指教, 我正在学习perl  ^_^

[ 本帖最后由 seawolf1979 于 2006-1-9 20:18 编辑 ]

论坛徽章:
0
7 [报告]
发表于 2006-01-09 21:43 |只看该作者
如果用不了crontab只能是你每天定时访问服务器上的抓取内容的脚本来更新.

论坛徽章:
0
8 [报告]
发表于 2006-01-09 21:59 |只看该作者
这个太麻烦了. 呵呵

我的脚本已经弄好了.
贴出来大家共享一下:           还有一个是问题就是LWP不能进行代理验证?  我用的proxy需要用户名和密码的, 有解决方法么? 谢谢

-----------------------------------------perl script on client
#!/usr/bin/perl -W

use warnings;
require LWP::UserAgent;
use HTTP::Request::Common;
my $browser = LWP::UserAgent->new();
my $url = 'http://10.193.101.250/twiki/bin/psupload';
my $res=$browser->post( $url,
[FILE1 => ["/home/seawolf/zisaohaiyouni.mp3"],
FILE2=> ["/home/seawolf/xconfigure.txt"]],
'Content_Type'=>'form-data');
#die "URL Error: ", $res->status_line unless $res->is_success;
print $res->content;
-----------------------------------------------------------------

-----------------------------------------------perl script on server
#!/usr/bin/perl
use CGI;

$upfilecount = 1;

$maxuploadcount = 2;

$basedir = "/var/www/twiki/bin";

$allowall = "yes";

@theext =(".zip",".exe",".gif");

print "Content-type: text/html\n\n";

while ($upfilecount <= $maxuploadcount) {
        my $req = new CGI;
        my $file = $req->param("FILE$upfilecount");

        if ($file ne "") {
          my $fileName = $file;
          $fileName =~ s/^.*(\\|\/)//;
          my $newmain = $fileName;
              my $filenotgood;

          if ($allowall ne "yes") {
             $extname = lc(substr($newmain,length($newmain) - 4,4));
             for(my $i = 0; $i < @theext; $i++){

           if ($extname eq $theext[$i]){
             $filenotgood = "yes";
             last;

           }
   }
}

if ($filenotgood ne "yes") {
        open (OUTFILE, ">$basedir/$fileName");
        binmode(OUTFILE);

        while (my $bytesread = read($file, my $buffer, 1024)) {
                print OUTFILE $buffer;

}

close (OUTFILE);

$message.=$file . " OK!\n";

}

else{

$message.=$file . " Failed!\n";

}
}

$upfilecount++;
}



print $message;

-----------------------------------------------------------------
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP