How to use wget to download files from Onedrive? (and batch files and entire folders, if possible)
-
1Please take a look at superuser.com/questions/833199/… "In Office 365 how do I get a direct download link for an Excel document stored in One Drive for Business?" to see if that answers your question.– steveAug 17, 2015 at 16:08
-
But is necessary subscripted account in Office365.– charlesAug 17, 2015 at 16:48
-
1Use the OneDrive client that someone has kindly written for Linux ? github.com/xybu/onedrive-d-old– steveAug 17, 2015 at 16:53
-
Try to download the file to your browser, while the download is running, right click and 'copy download link'. If you are lucky you can wget that link.– BaazigarAug 17, 2015 at 18:33
-
I try Onedrive-d, but couldn't do 'get' work. Really by copying link to file and put in 'wget', it works, thank you.– charlesAug 17, 2015 at 20:12
9 Answers
Update on APRIL 2021: It looks like this solution NO LONGER WORKS WITH ONEDRIVE FOR BUSINESS.
There is one way that works for me (based on How to Make Direct Link of OneDrive Files)
Right-click on the file you are interested in download (from web interface), and choose Embed.
Press "Generate HTML code to embed this file".
Copy the part contained in the
""
of src is your link. This will look like <https://onedrive.live.com/embed?cid=6EBB03E38A53ED3E& resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA>.Replace
embed
withdownload
. This will look like https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA.Feed it to
wget
using following syntax (the quotes are required):wget --no-check-certificate "https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA"
Enjoy.
-
2One must not forget to put the link in
""
inwget
. I did and it didn't work. Mar 8, 2017 at 9:58 -
3
-
1Hello @Fedorov7890 it seems that the embed option is no longer available. Mar 19, 2021 at 11:56
-
3
-
1I had to add the string
&download=1
at the tail of the URL. Example: instead of usingwget --no-check-certificate "https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA"
I had to usewget --no-check-certificate "https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA&download=1"
Sep 9, 2021 at 19:57
Using Chrome (but Firefox will probably also work).
- Open DevTools
- Click the Download button.
- Download but cancel immediately
- Open the 'Network' tab in DevTools. Search for 'Zip?authKey=' in DevTools and open it (click). This is a POST request.
- Click 'View source' to the right of 'Form data' at the bottom.
- Construct the command as follows:
wget --post-data='<raw form data>' '<Download URL>'
Or:
wget --post-data='resIds=xxx&canary=yyy&authkey=zzz' 'https://cid--foobar.users.storage.live.com/downloadfiles/V1/Zip?authKey=zzz'
This even works on a different host (with a different IP address).
-
11A simpler variation on this (using Firefox) is: Tools->Web Developer->Network. Find 'Zip?authKey=', right click on it and 'Copy as cURL'. Copy-paste into the command line and add '-o /path/to/some/file'. Of course this uses cURL instead of wget, but for this purpose they function identically Dec 25, 2017 at 4:41
-
-
And how to do it automatically if there’s 100000 files to share? Apr 13, 2021 at 23:19
-
Thanks for the tip! @happyskeptic I guess something changed on the side of OneDrive. I am doing same thing but with the record which has "x-zip-compressed" in "Type" field.– PhilipJul 30, 2021 at 14:56
-
Yeah, there was no return for
Zip?authKey=
but I searched forzip
and it returned a couple of files with gzip in the metadata description. One file appeared to be empty by judging the icon next to the string. The other had what looked like a white piece of paper icon or a file icon next to it so I right clicked on that string and copied it. No need to use any special syntax, I just usedaria2c <url>
– mchidJan 21, 2022 at 0:05
generate a sharing link and append "&download=1" to the end of it.
e.g. if the link is "https://some.host/:z:/x/personal/some_user/123456asdf?e=12345"
then
wget "https://some.host/:z:/x/personal/some_user/123456asdf?e=12345&download=1"
-
1
-
4
-
This answer needs more upvotes and should be the selected answer. Especially since OneDrive doesnt offer the embed option for business accounts! Apr 13, 2021 at 2:59
-
1
-
If you are looking to download an entire publicly shared folder (without auth!): OneDeath
It uses wget to do some API calls and will then recursively download files. Bonus: sha1 checks of finished files.
Sharepoint is now also supported, but it's a little trickier (it currently fetches more files from a drive than what is shown by the link). A major problem was a slightly different API structure and the fact that the session token expires after 1h, but it's solved too. They also appear to have some rate-limiting in place, so don't start too many parallel downloads.
The script can extract ready-to-use wget
commands using the -w
parameter.
PS: If you are interested to know more about the web API, I will give a run down of the process.
- Open the link in web interface like Chrome.
- Click "Download" on the top left.
- At the bottom, click "Show All".
- Find the downloading or downloaded file, right click the long link and click "Copy Link Address".
- wget the long address in command line.
-
probably the only one working way to download some shared files if you don't want to install additional tools or bring the python code to extract objects Dec 10, 2020 at 13:26
-
@Hayden and how to do this if automatically if there’s 100000 files to share? Apr 13, 2021 at 23:21
-
@user2284570 Haven't tried that before. Maybe you can try this github.com/abraunegg/onedrive.– HaydenApr 14, 2021 at 18:11
-
@Hayden no I really need to have those bunch of generated links accessible by third party tools. Apr 14, 2021 at 21:15
This python SDK (with example) for OneDrive project works (for personal, business, and corporate accounts):
-
1The project is deprecated and the api it uses is disabled since 2019. Apr 13, 2021 at 23:20
You can embed the file and Replace embed with a download. This will look like https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA.
Now use PHP curl to get this file content
$download_url = "https://onedrive.live.com/download?cid=6EBB03E38A53ED3E&resid=6EBB03E38A53ED3E%21116&authkey=AC4lDqtLG8LqfiA";
$file_name = "test.xlsx";
$ch = curl_init($download_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$data = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$content_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$error = curl_errno($ch);
curl_close($ch); // A file with the same name may exist, that must be handled. $file_save_path = $file_name;
file_put_contents($file_save_path, $data);
echo 'File successfully retrieved and stored!';
I actually have an alternative solution:
- set-up OneDrive on you computer. This won't download the files on your local machine so don't need to worry about disk space.
- open a terminal window in the OneDrive folder on your computer then you can copy the contents of a specific folder like this:
cp -r <MY_BIG_ONEDRIVE_FOLDER>/ <MY_DESTINATION_FOLDER>
Where <MY_BIG_ONEDRIVE_FOLDER>
is the name of the OneDrive folder you want to copy files from and <MY_DESTINATION_FOLDER>
is the destination folder.
I'm actually using this approach right now while I'm writing this post to copy +200Gb of files from my OneDrive folder to my external hard-drive.