How to download protected files from onedrive using WGET
Asked Answered
C

5

6

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"
Christophany answered 29/6, 2020 at 8:36 Comment(0)
S
14

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

  1. Open the URL in either of the browser.
  2. Open Developer options using Ctrl+Shift+I.
  3. Go to Network tab.
  4. Now click on download. Saving file isn't required. We only need the network activity while browser requests the file from the server.
  5. A new entry will appear which would look like "download.aspx?...".
  6. Right click on that and Copy → Copy as cURL.
  7. 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.

An example of the command:

 curl 'https://company-my.sharepoint.com/personal/path/_layouts/15/download.aspx?SourceUrl=
 %2Fpersonal%2Fsome%5Fpath%5Fin%2Ffile' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux 
 x86_64; rv:73.0) Gecko/20100101 Firefox/73.0' -H 'Accept: text/html,application/xhtml+xml,
 application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' 
 --compressed -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: https://company-my
 .sharepoint.com/personal/path/_layouts/15/onedrive.aspx?id=%2Fpersonal%2Fagain%5Fa%5Fpath%2F
 file&parent=%2Fpersonal%2Fpath%5Fagain%5Fin%2&originalPath=somegibberishpath' -H 
 'Cookie: MicrosoftApplicationsTelemetryDeviceId=someid; 
 MicrosoftApplicationsTelemetryFirstLaunchTime=somevalue; 
 rtFa=rootFederationAuthenticationCookie; FedAuth=againACookie; CCSInfo=gibberishText; 
 FeatureOverrides_enableFeatures=; FeatureOverrides_disableFeatures=' -H 
 'Upgrade-Insecure-Requests: 1' -H 'If-None-Match: "{some value},2"' -H 'TE: Trailers' 
 --output file.extension

Sil answered 23/1, 2021 at 17:48 Comment(0)
Y
1

This is in curl. Assuming you used OneDrive to get the shared URL that is viewable by anyone with the link e.g.

https://1drv.ms/u/s!Apdrsccw-Aino61diDib9li1_wXtwQ?e=SAMPLE

Then you use

sharedUrl='https://1drv.ms/u/s!Apdrsccw-Aino61diDib9li1_wXtwQ?e=SAMPLE'
curl -sL 'https://api.onedrive.com/v1.0/shares/u!'$(echo -n "$sharedUrl" | base64 -w0 | tr -d '=' | tr '/+' '_-')/driveItem/content
Yates answered 4/8, 2023 at 0:37 Comment(0)
D
0

I know I'm a bit late and the question doesn't ask for a python solution.

But I tried searching everywhere for a solution that works for OneDrive for business and none worked, so I made a python script that does it and works on OneDrive for business:

Onedrive-Private-PDF-Downloader

Deaminate answered 15/6, 2023 at 20:18 Comment(0)
P
0

Solution that worked for me to get a direct download link for a video hosted on OneDrive protected with a password:

  1. Open the video link and fill in password when prompted as normal
  2. Start playing video
  3. Open dev tools and look for a network request that fetches a video chunk. It should look like https://public.db.files.1drv.com/{ID}?videoformat=dash&track=video&quality=video-1080p
  4. Remove all query parameters (everything after the ? in the url). Now when you open the remaining https://public.db.files.1drv.com/{ID} url in the browser it should download the entire video. Should also be possible to use with wget etc.
Passe answered 12/11, 2023 at 21:58 Comment(0)
S
0

To download a shared file stored in OneDrive, you can use the following function:

onedrive_download() {
    local sharedUrl="$1"
    local destfile="$2"
    curl -sL 'https://api.onedrive.com/v1.0/shares/u!'$(echo -n "$sharedUrl" | base64 -w0 | tr -d '=' | tr '/+' '_-')/root/content -o $destfile
}

onedrive_download https://1drv.ms/i/s!Ar_Hlkz5yHsbkDMJx40gmwVkyLld?e=IHQBpm picture.jpg
Slapbang answered 8/12, 2023 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.