Solved

Location redirection to FTP file

Posted on 2000-05-18
6
257 Views
Last Modified: 2013-12-25
I've written a Perl script to handle redirection from my site to files hosted on another website.

I've used
print "Location: http://www.etc.com/file.hqx", "/n/n"; which works with no problems

However, some of the files I wish to relocate to are hosted on an FTP server.
When I try print "Location: ftp://ftp.etc.com/file.zip","/n/n";
the file downloads ok, but the filename and type are set incorrectly. Instead of the download being called file.zip I get redirect.pl (the name of my script). If I rename the file on the desktop file.zip I can decompress the file ok.

I'm using IE5 on the mac to try this.

Any help appreciated

0
Comment
Question by:bodoni
  • 4
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2821215
you can fix this problem by appending the name of the downloaded file to the end of your PERL script.

Lets say the URL that does is redirection is...

http://www.yourserver.com/cgi-bin/redirect.pl

just change it to ....

http://www.yourserver.com/cgi-bin/redirect.pl/file.zip

and then try.

NOTE: this solution does not work on NT with IIS4.0 since IIS does not support appending  anything after the script name.
=============================================
Another approach that works across systems, assuming you are sending the MIME header across is the foll.

In the headers which you output, you could try putting the following:
print "Content-type: application/octet-stream\n";
print "Content-disposition: filename='file.zip'\n\n"


Hope that helps.
0
 

Author Comment

by:bodoni
ID: 2824885
maneshr,
 Thanks for the help so far... Ive tried both suggestions, but neither worked.
  Appending the filename didn't change anything.
  Adding the MIME headers did't work either. Each time the file downloads ok, but the filename and type are wrong.

I've tried the original script browsing from IE5 on the PC, and Netscape 4 on the mac and both work fine. Typical.....

Trying various combinations, I have to have narrowed the problem down. It looks like the remote site is having no problem naming the file, but for some reason IE5 on the mac is hasn't realised the location and filetype has changed. All I get in the download manager is redirect.pl as the filename.

Lee
0
 

Author Comment

by:bodoni
ID: 2824981
I've found the answer

print "Content-type: application/zip\n";
print "Content-disposition: file; filename=file.zip\n";
print "Content-location: ftp://ftp.etc.com/file.zip", "\n\n";

Works fine....

Hooray

This has the right filename, and filetype

Content-type: application/octet-stream didn't arrive as a zip file and I has to decompress the file manually.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:bodoni
ID: 2825370
Here we go again.
I was a bit hasty saying everything worked.
I've just checked the file that downloaded and its completely blank (0 bytes)

Using Content-type & Content-disposition headers and Location: the file downloads ok, but the wrong filename and type

It's as though IE5 is ignoring the type and filename, whatever you tell it.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2825661
"....I was a bit hasty saying everything worked. ...."

Don't worry. if in the end you dont get a working answer, i will refund you your points.

Right now, when you go to the ftp site, do you usually provide some kind of username/password?



0
 

Author Comment

by:bodoni
ID: 2826478
maneshr,

The FTP site has anonymous access so I don;t think there is a problem there.

I've kind of got a workaround that will have to do.

The script I was writing was to try and centralize downloading files from remote sites.

So a link from the web page would be
http://www.mysite.com/redirect.pl?NEW_URL=macsoftware
or http://www.mysite.com/redirect.pl?NEW_URL=pcsoftware

The script would then point to the correct location of the file depending on the argument. That means I only have to change the script file if any of the locations change and not individual web pages.

If I have the link on the web page as http://www.mysite.com/redirect.pl/newfile.zip?NEW_URL=pcsoftware I get the right filename, but the wrong filetype ( IE5 thinks its an IE file)

Previously I was adding the filename after the ? arguments.

It's not ideal, as the user would have to decompress the file manually, but at least is should be fairly obvious to do so.

Thanks for your help
Lee
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo‚Ķ
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now