472,969 Members | 2,228 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

HTTP file download

Hello,
I have written this code to make a file local before start working on it.
But when i execute it is not copying the file to local. I am getting 401 error.
could you please let me know whats wrong with this code.
thaks in advance.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use LWP::Simple;
  3.  
  4. my $filename = "http://sample.com/secure/sample.xls";
  5.  
  6. MakeFileLocal($filename);
  7.  
  8. sub MakeFileLocal {
  9.   my $filename = shift;
  10.  
  11.   chomp($filename);
  12.  
  13.   $filename =~ m/.*\.(.*)$/;
  14.   my $suffix = $1;
  15.   print "Suffix : $suffix\n";
  16.   my $newname = "d:/test/mohan/temp.$suffix";
  17.  
  18.   unlink("$newname");
  19.  
  20.   if ($filename =~ m/^http/i) {
  21.     print "Name matches starts with http://\n";
  22.     my $retval = getstore($filename, $newname);
  23.     die "Could not store it!!\n" unless is_success($retval);
  24.   } else {
  25.     my $cmd = qq~copy "$filename" "$newname"~;
  26.     print "$cmd\n";
  27.     my @a = `$cmd`;
  28.     }
  29.  
  30.   if (-e "$newname") {
  31.     return $newname;
  32.   }
  33.  
  34.   return 0;
  35.   }
  36.  
Nov 7 '08 #1
8 6585
KevinADC
4,059 Expert 2GB
401 is document not found error. Are you sure the URI to the remote file is correct?

http://sample.com/secure/sample.xls
Nov 7 '08 #2
401 is document not found error. Are you sure the URI to the remote file is correct?

http://sample.com/secure/sample.xls
hello Kevin,
Document is available at the same url.
when i use the same url in browser it is asking me to save or open it through file download alert message box.
Nov 7 '08 #3
KevinADC
4,059 Expert 2GB
Hard to say, is there a firewall or proxy server maybe causing the error?
Nov 7 '08 #4
the server is a microsoft biztalk server.
So i am not sure about whether any firewall behind it.
As it is a corporate machine i believe definitely there will be firewall.
If a firewall is available does it block such type of requests.
I dont have much knowledge on firewalls working.
thanks in advance.
Nov 7 '08 #5
KevinADC
4,059 Expert 2GB
I don't know enough to be able to help you with firewall problems. I just tested your code and it works for me:


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use LWP::Simple;
  3. my $filename = "http://www.e-pixs.com/smilies/smiley10.gif";
  4. MakeFileLocal($filename);
  5. sub MakeFileLocal {
  6.   my $filename = shift;
  7.   chomp($filename);
  8.   $filename =~ m/.*\.(.*)$/;
  9.   my $suffix = $1;
  10.   print "Suffix : $suffix\n";
  11.   my $newname = "c:/perl_test/smiley10.$suffix";
  12. #  unlink("$newname");
  13.   if ($filename =~ m/^http/i) {
  14.     print "Name matches starts with http://\n";
  15.     my $retval = getstore($filename, $newname);
  16.     die "Could not store it!!\n" unless is_success($retval);
  17.   } else {
  18.     my $cmd = qq~copy "$filename" "$newname"~;
  19.     print "$cmd\n";
  20.     my @a = `$cmd`;
  21.     }
  22.   if (-e "$newname") {
  23.     return $newname;
  24.   }
  25.   return 0;
  26.   }
  27.  
the script got the gif from the site and stored it on my server.
Nov 7 '08 #6
I don't know enough to be able to help you with firewall problems. I just tested your code and it works for me:


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. use LWP::Simple;
  3. my $filename = "http://www.e-pixs.com/smilies/smiley10.gif";
  4. MakeFileLocal($filename);
  5. sub MakeFileLocal {
  6.   my $filename = shift;
  7.   chomp($filename);
  8.   $filename =~ m/.*\.(.*)$/;
  9.   my $suffix = $1;
  10.   print "Suffix : $suffix\n";
  11.   my $newname = "c:/perl_test/smiley10.$suffix";
  12. #  unlink("$newname");
  13.   if ($filename =~ m/^http/i) {
  14.     print "Name matches starts with http://\n";
  15.     my $retval = getstore($filename, $newname);
  16.     die "Could not store it!!\n" unless is_success($retval);
  17.   } else {
  18.     my $cmd = qq~copy "$filename" "$newname"~;
  19.     print "$cmd\n";
  20.     my @a = `$cmd`;
  21.     }
  22.   if (-e "$newname") {
  23.     return $newname;
  24.   }
  25.   return 0;
  26.   }
  27.  
the script got the gif from the site and stored it on my server.
Hello Kevin,
Thank you very for your response.
From this discussion i got to know nothing wrong in the code i have written.
The only problem is may be due to firewall or proxy server.
I will discuss this thing further with that server administrator.
Nov 7 '08 #7
KevinADC
4,059 Expert 2GB
OK, you're welcome, good luck.

Kevin
Nov 7 '08 #8
OK, you're welcome, good luck.

Kevin
Hello,
As i am getting 401 error, i tried to understand the reason behind this error.
i found it will come if we don't have access to the particular links

[HTML]<a href="http://en.wikipedia.org/wiki/HTTP_401"> 401 error </a>[/HTML]

So later i modified my code so that it will send authentication details as well.
and when i requested my administrator he was telling i am having read access to the directory from where i am going to download the file.
so my new script is as follows.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl 
  2. use LWP::UserAgent;
  3. #my $url = 'http://si-airbag-www.de.bosch.com/cpc/Default.aspx'; 
  4. my $url = 'http://boschbiz.us.bosch.com/sites/projcentral/1810/Secured%20Engineering/60.Software/A.SW_Project_Management/00.%20Schedule/DC10_60_A_00_SW_Schedule_Full.mpp'; 
  5. my $ua = new LWP::UserAgent(keep_alive=>1);
  6. $ua->no_proxy;
  7. #$ua->agent('MSIE/6.0');
  8. $ua->credentials('sample.com:80','sites','mohan' => 'mohan123');
  9. $ua->timeout(15);
  10. my $request = HTTP::Request->new('GET');
  11. $request->url($url); 
  12. my $response = $ua->request($request);  
  13. my $code = $response->code; 
  14. print "Return Code ====>\n $code\n";
  15. my $headers = $response->headers_as_string;
  16. #If the Error is 401.2 then, 
  17. #The authentication methods that were tried are either disabled, or you are attempting to use NTLM through a proxy server.
  18. print "Headers ======>\n $headers\n";
  19. # HTML body:
  20. my $body =  $response->content;
  21. print "================\n$body====================\n";
i am getting the following output after executing the script.

Return Code ====>
401
Headers ======>
Date: Mon, 10 Nov 2008 04:53:08 GMT
Server: Microsoft-IIS/6.0
WWW-Authenticate: NTLM
Content-Length: 1656
Content-Type: text/html
Content-Type: text/html; charset=Windows-1252
Client-Date: Mon, 10 Nov 2008 04:53:08 GMT
Client-Peer: 10.24.250.27:80
Client-Response-Num: 1
Client-Warning: Unsupported authentication scheme 'ntlm'
MicrosoftSharePointTeamServices: 12.0.0.6219
Set-Cookie: RBNA_Boschbiz_07=R731053916; path=/
Title: You are not authorized to view this page
X-Powered-By: ASP.NET

================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<HTML><HEAD><TITLE>You are not authorized to view this page</TITLE>

<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">

<STYLE type="text/css">

BODY { font: 8pt/12pt verdana }

H1 { font: 13pt/15pt verdana }

H2 { font: 8pt/12pt verdana }

A:link { color: red }

A:visited { color: maroon }

</STYLE>

</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD>



<h1>You are not authorized to view this page</h1>

You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

<hr>

<p>Please try the following:</p>

<ul>

<li>Contact the Web site administrator if you believe you should be able to view this directory or page.</li>

<li>Click the <a href="javascript:location.reload()">Refresh</a> button to try again with different credentials.</li>

</ul>

<h2>HTTP Error 401.2 - Unauthorized: Access is denied due to server configuration.<br>Internet Information Services (IIS)</h2>

<hr>

<p>Technical Information (for support personnel)</p>

<ul>

<li>Go to <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>401</b>.</li>

<li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr),

and search for topics titled <b>About Security</b>, <b>Authentication</b>, and <b>About Custom Error Messages</b>.</li>

</ul>



</TD></TR></TABLE></BODY></HTML>
====================

and anybody could let me know whether the new code is correct, i mean the way i am sending the authentication details.

And one more thing i want to know is how can we make sure the http request we are making is going through proxy?

thanks a lot in advance.

Best Regards,
Mohan
Nov 11 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Michael Foord | last post by:
I'm creating a CGI that offers files for download. After googling I though I had the right headers to send to force a download - but it sends the data to the browser instead of opening the download...
3
by: Derrick | last post by:
I have an http download that streams a zip file to client, after download I am getting "Error start of central directory not found; Zip file corrupt. Possible casue: file transfer error." Ring...
1
by: Silvia | last post by:
I have this code in web.config file <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="dllredirect"/> <codeBase...
2
by: Derrick | last post by:
Anyone been able to get a multi file HTTP download working with ASP? I have a single file download working fine with the usual setting the content type, file name, stream the file from...
0
by: Chuck Anderson | last post by:
I am writing a Php script to run on my home PC (Windows) that downloads an Apache access log file and inserts new entries into a database.. The only way I can access these log files is through a...
0
by: Owen Jenkins | last post by:
I've been using Dev's fantastic InetTransferLib to upload and download files via ftp. Now I'm using the http procedures to have my application download zip files from my website. Although the...
1
by: Owen Jenkins | last post by:
Reposting this message from last week since I have not had a reply so far. Hopefully someone will have an idea? --- I've been using Dev's fantastic InetTransferLib to upload and download files...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
2
by: Dmitry Duginov | last post by:
I wrote HTTP module and configured it to fire with every request to my application. In IIS6 aspnet_isapi.dll mapped as Application Extension, web.config contains the following: <system.web> ...
0
by: Rhys666 | last post by:
Basically I have a link that opens my download page and the querystring identifies the type of 'template' Excel spreadsheet has asked to download. The download page reads the querystring,...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.