首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从URL同时下载文件

从URL同时下载文件
EN

Stack Overflow用户
提问于 2022-11-18 21:35:54
回答 1查看 41关注 0票数 -1

我们有一个perl脚本,可以从不同的服务器下载文件。目前要花上几个小时。在哪里可以找到一种同时下载多个文件的方法。谢谢你谢尔盖。

我仍然试图从开发团队获得全部细节,但我正在寻找一些提示。

代码语言:javascript
复制
sub getConfData {
    my $mech = WWW::Mechanize->new( autocheck => 1 );

    print "USER NAME :- $Inputs::conf_user\n";
    print "USER PASS :- $Inputs::conf_pass\n";

    $mech->credentials( "$Inputs::conf_user" => "$Inputs::conf_pass" );
    logs( $Inputs::logpath, "Opening the URL of confD : $Inputs::conf_url" );
    print "Opening the URL of confD : $Inputs::conf_url\n";
    
    $mech->mirror( $Inputs::conf_url, $Inputs::conf_arch );

    my $next = Archive::Tar->iter( $Inputs::conf_arch, 1, { filter => qr// } );
    my $confdName = $next->()->name;
    logs( $Inputs::logpath, "confD Downloading Filename is  : $confdName" );
    print "confD Downloading Filename is  : $confdName\n";
    my $tar = Archive::Tar->new();
    $tar->read($Inputs::conf_arch) or die logs( $Inputs::errorpath, " Unable to read the TAR file." );
    $tar->extract();

    my $destination = "$Inputs::download_path" . "$Inputs::confddb";
    rmtree($destination);
    my $cwd = getcwd();
    move_reliable( "$confdName", "$destination" ) or logs( $Inputs::errorpath, " unable to move folder to $destination." );
    logs( $Inputs::logpath, "Moving confD $confdName to $Inputs::download_path" . "$Inputs::confddb" );
    print "Moving confD $confdName to $Inputs::download_path $Inputs::confddb\n";

    if ($@) {
        my $message = "Failed to pull confd data and write it to $Inputs::download_path :: $@";
        send_mail( $Inputs::from, $Inputs::to, $Inputs::error_subject, $message );
        logs( $Inputs::errorpath, " $message" );
        die("$message");
    }
    else {
        unlink $Inputs::conf_arch or die logs( $Inputs::errorpath,"COULD NOT UNLINK $Inputs::conf_arch" );
        unlink $destination;
       }
   }


 
    foreach my $server (@productList) {
           my $pid;
           if ( defined( $pid = fork ) ) {
               if ( !$pid ) {
                   exec("$main_file $server &");
                   die "Error executing command: $!\n";
               }
           }
           else {
               die "Error in fork: $!\n";
              }
           }
 
       logs( $Inputs::logpath, "Downloading config started at :" . datetimes( 'dtime', 'db' ) );
        &getConfData();
       logs( $Inputs::logpath, "Downloading config completed at :" . datetimes( 'dtime', 'db' ) );

        print "Downloading config Completed at : "`your text`. datetimes( 'dtime', 'normal' ) . "\n";
        logs( $Inputs::logpath, "Downloading config completed at :" . datetimes( 'dtime', 'db' ) );
EN

回答 1

Stack Overflow用户

发布于 2022-11-21 17:03:31

Mojo::UserAgent与接受承诺的方法一起使用。有关扩展示例,请参见你答应给我打电话

您也可以在Perl中使用一些其他并发性,但是由于Mojolicious内置了它,所以我将使用它。

或者,您可以非常喜欢使用仆从。每个链接都被插入到作业队列中。这样,您可以很容易地标记哪些您需要重试,等等。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74495566

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档