Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sorry if this is unclear, but I'm trying to set up a script that downloads a file. Currently, my method of downloading the file is by clicking on a link like so:

https://www.URL.com/view?downloadFile=AcctItemFiles\1234567890.txt

I tried using a wget command but that obviously didn't work because that link is not an actual file location. Any ideas on how to either figure out the actual file location or how to download the file with that link would be helpful.

share|improve this question
    
What do you mean "not an actual file location"? Do you mean that you have to read the HTML to figure out what the URL is? Do you mean that after clicking on that URL you're taken to another page that has the "actual file location" on it? –  DerfK Jun 3 '11 at 18:18
    
I mean that the URL invokes a GET command to download the file. In other words, the file is not named "view?downloadFile=AcctItemFiles\1234567890.txt" nor located in the base directory for the domain. Going to the link doesn't bring you to any page, it just runs the GET command and begins downloading. –  Nick Jun 3 '11 at 18:31

2 Answers 2

up vote 2 down vote accepted

wget should have no problem fetching it, since it performs the GET command just fine on a URL like that. The only problems I can think of that you might be having are:

  • that \ is a special shell character and you will need to put the URL in quotes in order to prevent the shell from converting \1 to 1. Better yet, escape \ characters as %5C
  • wget is naming the file view?downloadFile=AcctItemFiles\1234567890.txt instead of something sane like your web browser does. Either use the -O filename option to force it to write all the downloaded data to a specified filename eg

(interesting... a code block cannot follow a bullet point)

wget -O 1234567890.txt "http://www.whatever.com/view?downloadFile=AcctItemFiles\1234567890.txt" 

Or, use the --content-disposition option to tell it to save using the filename provided by the server in the header (read and understand the warning about it being buggy and about it requiring two requests. Do not use this if the target script does not support the HEAD command) Alternatively, use curl -O -J ... instead of wget, where -O -J together instruct it to read the output filename from the header. The documentation does not say that curl requires two requests, but curl recently had a vulnerability due to trusting invalid filenames, so "buggy" may still apply.

share|improve this answer
    
Thanks, I think it was working correctly in the first place and named the file view?downloadFile=AcctItemFils\1234567890.txt and I just assumed it had downloaded improperly. Just to be safe, I also escaped the \. After renaming the file and running it in nano, it worked fine. –  Nick Jun 3 '11 at 20:32

Try using curl with the '-L' flag instead of wget.

   -L/--location
          (HTTP/HTTPS) If the server reports that the requested page has moved to a   different location (indicated with a Location: header and a 3XX response code), this  option  will
          make  curl  redo the request on the new place.

Curl and wget complement each other.

share|improve this answer
    
Tried this and nothing occurs unfortunately. –  Nick Jun 3 '11 at 18:34
    
Alas. Your current example does not open for me in the browser, just times out, do you have another one? –  Ivan P Jun 3 '11 at 18:37
    
Sorry, I've had to change the URL because the file itself is sensitive information. I'm under contract to not disclose it to others. Unfortunately I can't provide you with another example. –  Nick Jun 3 '11 at 18:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.