2012-05-15 3 views
0

*** 이력서 기능을업데이트 된 코드* *다운로드하는 방법`decoded_content`

my $ua = LWP::UserAgent->new; 
    $ua->credentials('$ip:80', 'Realm', 'username', 'password'); 
    my $response = $ua->mirror($url,$newfile); 
    if ($response->is_success) { 
     print "Download Successfull."; 
    } 
    else { 
     print "Error: " . $response->status_line; 
    } 

** * ** * * *이전 코드* ** * ** * ** * ** * ** * *

my $ua = LWP::UserAgent->new; 
    $ua->credentials('$ip:80', 'Realm', 'username', 'password'); 
    my $response = $ua->get($url); 
    if ($response->is_success) { 
     print "Retrieved " .length($response->decoded_content) . 
      " bytes of data."; 
    } 
    else { 
     print "Error: " . $response->status_line; 
    } 

open my $fh, '>encoding(UTF-8)', $tmp; 
print {$fh} $response->decoded_content; 
close $fh; 

if (-e $tmp) { 
    my $filesize = (stat $tmp)[9]; 
    my $origsize = $queue[$rec][1]; 

    if ($filesize < $origsize) { 
     print "Resuming download"; 
    ****************************************** 
    code for resuming the partly downloaded file... 
    ******************************************* 
    } 
    else { 
     print "File downloaded correctly\n"; 
    } 
} 

내가 펄 안돼서으로 , decoded_content을 다운로드 할 수 있습니다, 일부 오류는 계속 발생하지만. 부분 파일이있는 경우 파일 다운로드를 다시 시작해야합니다.

이것은 내가 시도한 코드이지만 어디서부터 시작할 것인지 알 수 없으므로이 점에 대한 빠른 생각은 실제로 큰 도움이 될 것입니다. 이걸 도와주세요.

+0

어쩌면 책을 읽기 시작해야 할 것입니다. 어때? [이 하나] (http://www.amazon.com/Learning-Perl-Randal-L-Schwartz/dp/1449303587/ref=sr_1_1?ie=UTF8&qid=1337074010&sr=8-1) –

+0

읽고 나서 [편집] (http://stackoverflow.com/posts/10597630/edit) stackoverflow에 맞게 귀하의 질문. –

답변

1

method mirror in LWP::UserAgent을 참조하십시오. 문서 인용문 :

이 방법은 $ url로 식별 된 문서를 가져 와서 $ filename이라는 파일에 저장합니다.

my $response = $ua->mirror($url, $filename); # no single quotes around variables! 

는 잘립니다/부분적으로 다운로드 한 파일을 올바르게 취급의 source code for mirror 참조하십시오.

+0

Daxim은 귀하의 빠른 도움에 감사드립니다. 위에서 언급 한 방법으로 파일을 로컬 디렉토리에 다운로드했습니다. 하지만 "print() print.files()에 대한 다운로드 파일을 닫습니다. $ fh at download.pl" 이제 부분적으로 다운로드 한 파일을 임시 디렉토리에서 다시 시작했습니다. –

+0

다시 감사합니다. Daxim, 내가 어떻게 당신의 응답을 간과했는지. 거울()은 잘 작동하고 내 요구 사항에 맞습니다. 수정 된 코드를 추가했습니다 :) –

관련 문제