How to download a file with string in name using perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Srijith B
    New Member
    • Jan 2011
    • 20

    How to download a file with string in name using perl

    Im trying to write a perl code to do the following task.

    I have a website which is located in a diffirent country.
    I want to download a file from that site everyday.
    The file name keeps on changing everyday.
    say the file name is CTP-latest-5.3.0.37.iso
    next day it may change to "CTP-latest-5.3.0.38.iso" or remain same.

    I want to download only if the version number (ie. 38 in above example("38.iso ") is not the same from last sucessful download or else dont download.

    Im very poor in perl, can someone help me on this ?

    i tried with
    Code:
    #!/usr/bin/perl 
    
    use LWP::Simple; 
    
    #-- fetch the zip and save it as perlhowto.zip 
    my $status = getstore("http://star.mywebsite/CTP-LATEST-4.4.4.37.iso", "CVP-LATEST-5.3.0.37.iso"); 
    
    if ( is_success($status) ) 
    { 
    print "file downloaded correctly\n"; 
    } 
    else 
    { 
    print "error downloading file: $status\n"; 
    }
    This works fine in downloading the file, But I need to have a check on version number. So I want to download only if the version number has been changed from the version number of previous successful download.


    one idea is if we want to download "CTP-LATEST-4.4.4.37.iso" but the file is not available the download fails and we catch the error and we dont increment the value "37" however we are trying with the same value ("37") tommorow. so if ....37.iso is available tommorow then we download and increment the value 37 to 38.iso and store it.


    thank you for your time.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    1) Use LWP to download the webpage that actually links to the file.
    2) Parse that file to determine the current resource version
    3) Download that file if it's different from the previously downloaded resource.

    - Miller

    Comment

    • Srijith B
      New Member
      • Jan 2011
      • 20

      #3
      HI miller , you said
      "Parse that file to determine the current resource version"

      Is it possible to determine the time stamp of that page instead determining the resource version ?

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Use the head function in LWP::Simple to retrieve the modified timestamp.

        Comment

        Working...