'How to download protected files from onedrive using WGET

I need to download an excel spreadsheet from Onedrive shared location to our unix server using WGET or CURL. I am able to download an un-protected link without issues:

wget "https://...&download=1"

but I would prefer to have the file protected, either by password or by allowing access only to people in our company.

The issue is, I am unable to download such protected file using WGET, the --password option is not accepted:

wget --password=abc "https://...&download=1"


Solution 1:[1]

Google Chrome or Mozilla Firefox both provide an option to copy download link specifically for cURL. This option will generate a cURL with all required things such as User-agent for downloading things from the side. To get that,

  • Open the URL in either of the browsers.
  • Open Developer options using Ctrl+Shift+I.
  • Go to Network tab.
  • Now click on download. Saving file isn't required. We only need the network activity while the browser requests the file from the server.
  • A new entry will appear which would look like "download.aspx?...".
  • Right-click on that and Copy ? Copy as cURL.
  • Paste the copied content directly in the terminal and append --output file.extension to save the content in file.extension since terminal isn't capable of showing binary data.

example:

curl 'https://xyz.sharepoint.com/personal/someting/_layouts/15/download.aspx?UniqueId=cefb6082%2D696e%2D4f23%2D8c7a%2 .... some long text .... cCtHR3NuTy82bWFtN1JBRXNlV2ZmekZOdWp3cFRsNTdJdjE2c2syZmxQamhGWnMwdkFBeXZlNWx2UkxDTkJic2hycGNGazVSTnJGUnY1Y1d0WjF5SDJMWHBqTjRmcUNUUWJxVnZYb1JjRG1WbEtjK0VIVWx2clBDQWNyZldid1R3PT08L1NQPg==; cucg=1' --compressed --output file.extension

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 José Luis Marrero