0

I am trying to download a file protected by htaccess password:

This is my code from my test.sh file

#!/bin/sh
powershell -Command "(New-Object Net.WebClient).DownloadFile('http://myuser:mypassword@servername.nl/path/to/file/call.csv', 'file.csv')"
powershell -Command "Invoke-WebRequest http://myuser:mypassword@servername.nl/path/to/file/call.csv -OutFile file.csv"

If I access it from the browser it works. But from the console by running the command: sh test.sh I got this error:

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Any idea how can I fix this?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Attila Naghi
  • 2,535
  • 6
  • 37
  • 59
  • If you're operating from bash you'd probably be better off using the `curl` or `wget` command (e.g. `curl -u myuser:mypassword -o file.csv http://servername.nl/path/to/file/call.csv`). – Ansgar Wiechers Jun 27 '18 at 18:26
  • The error suG/ests that your browser has sme information (cookies, authentication tnkens, etc?) that you are not supplying on the command line. Without knowledge about the specific server you are trying to access, we have no idea beyond this, and no way to find out. – tripleee Jun 28 '18 at 03:49
  • I'm tempted to edit out the Bash/`sh` parts because the problematic parts are obviously Powershell. Is there a reason you don't simply put these commands in a Powershell script anyway? – tripleee Jun 28 '18 at 03:50
  • It will be on the windows server, but right now I am testing it from windows 10 – Attila Naghi Jun 28 '18 at 06:38
  • @AnsgarWiechers don't have installed wget or curl on windows 10 . It would be much more easy :) – Attila Naghi Jun 28 '18 at 06:39
  • Windows ports of both `wget` and `curl` exist, e.g. https://curl.haxx.se/download.html. – Ansgar Wiechers Jun 28 '18 at 07:06

0 Answers0