Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grabbing binary files via http 1

Status
Not open for further replies.

Nebbish

Programmer
Apr 7, 2004
73
US
Hey folks, an easy one- how do I download binary files through a URL? I know how to use LWP::Simple to "get" a web document, but if the file is binary it doesn't read it properly.

IE, want to use Perl to automate the downloading of a .zip file, at How do I do it?

Thx,

Nick
 
This might help. I had to add in the multiple attempts due to an issue with the server I was grabbing information from. (It was sporadically available at night)

Code:
my $url = "[URL unfurl="true"]http://server/binaryfile.ext";[/URL]
my $file = "c:\\My Documents\\binaryfile.ext";

my ($rc, $status);

print qq(Starting Retrieval\n);

my $loop = 1;
my $count = 1;
my $max_count = 20;

while ($loop)
{
	if ($count == $max_count)
	{
		$loop = 0;
		last;
	}

	$rc = getstore($url, $file);

	$status = status_message($rc);

	print qq(Return Code: $rc\tStatus: $status\n);

	if (is_success($rc))
	{
		print qq(Received file\n);
		exit;
	}
	elsif (is_error($rc))
	{
		$count++;
		next;
	}
}

print qq(File Retrieve Failed after $max_count attempts.\n);

- Rieekan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top