
Mortimer
journeyman
Jun 23, 2001, 8:27 AM
Post #5 of 8
(718 views)
|
|
Re: Check if file exists with only URL
[In reply to]
|
Can't Post
|
|
Hello Marcus. Well I wouldn't call it a problem, and you can't get around it (nicely), you have to be authorized for this. You can have the LWP::UserAgent module's authorization_basic() method verify that you're authorized to mess with a file...
use LWP::UserAgent; my $locf = "/path/to/local/file.ext"; my $f = 'http://www.domain.com/path/to/serverfile.ext'; my $r = new HTTP::Request 'GET', $f; my $ua = new LWP::UserAgent; $r->authorization_basic( 'username', 'password' ); my @lines = map{ $_ } split ($/), $ua->request( $r )->content; #$ua->mirror( $f, $locf ); # If accessing non .htaccess dirs open( FILE, ">$locf" )or die( "Can't open $locf: $!" ); print FILE @lines; close( FILE ); If you're not authorized, the server will tell you. If you are authorized and the file doesn't exist, you'll just get the 404 Not Found message. For some reason we can't mirror() the files in .htaccess protected directories even if we're authorized. If we want to save the data, we have to create a file with open(). Cheers, Dave. www.dmscripts.com davemortimer@bigpond.com
|