How to download files off the web with Perl?
July 15, 2007 1:26 PM   Subscribe

I am need help writing a Perl script that given the URL of a file (particularly image files) it downloads the file to a local directory I define.

I am doing this using XAMPP on my windows box, and is for a local script which generates a web page. Any advice would be apprecaited.
posted by LoopyG to Computers & Internet (6 answers total)
 
Will the URLs always be HTTP, or would they sometimes be FTP?

Is there a reason that you can't just use wget, curl, snarf, or another command-line program dedicated to this purpose?

I don't know off the top of my head how to do this in Perl, but I'm positive you'll find a file-downloading library if you search CPAN.
posted by zixyer at 1:31 PM on July 15, 2007


Probably the easiest way would be to get a program like wget or curl and invoke it from the Perl script with backticks.
posted by goingonit at 1:40 PM on July 15, 2007


Not really - use LWP::Simple.
posted by kcm at 2:02 PM on July 15, 2007


(Not to mention the difference between using system() vs. ``, etc. They are quite different.)
posted by kcm at 2:11 PM on July 15, 2007


This is a perl script that gets called by the browser. IE, I go to http://localhost/perl/myscript.pl and it gets done. And yes, the files will always be HTTP. Also, I am not sure how to call something like wget from a perl script.

Looking in LWP::Simple, I found a function I hadnt noticed before. Mirror() downloads the file all right, and I can even choose the folder. However, it doesnt let me move the file to a folder that doesnt exist.

So I guess the question to solve that is, how does one create a folder with Perl?
posted by LoopyG at 2:29 PM on July 15, 2007


Ack, never mind. With some googling I found the mkpath and move commands. Thanks everyone!
posted by LoopyG at 2:38 PM on July 15, 2007


« Older Excel dragging other files into the party...   |   What's the best way to pay for a sublease across... Newer »
This thread is closed to new comments.