Linux命令行下载OneDrive分享链接中的文件

何向荣
2023-12-01

我所知的某个游戏分享站喜欢用OneDrive来分享游戏,用OneDrive很好,抵制百度网盘我强烈支持,但是OneDrive国内有时候抽风比较厉害,而在国外OneDrive下载几乎能跑满带宽,我G口的服务器可以跑到110M/s,所以用国外服务器下载,然后再下载自己服务器里的东西会比较好。

但是因为OneDrive有些坑,无法从分享界面获取真实下载链接,比如下面这个链接

https://gitaccuacnz2-my.sharepoint.com/:f:/g/personal/mail_finderacg_com/EheQwACFhe9JuGUn4hlg9esBsKyk5jp9-Iz69kqzLLF5Xw?e=FG7SHh

点开之后,找个文件点击下载,会得到这样的下载链接:

https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/download.aspx?UniqueId=cb44677f%2Dc4af%2D44ad%2D88d4%2Dceb07d9625da

但是如果直接在服务器里 wget 这个下载链接,100%会403: Forbidden

最终得到的正确链接为:

curl 'https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/download.aspx?UniqueId=cb44677f%2Dc4af%2D44ad%2D88d4%2Dceb07d9625da' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: zh-HK,zh-TW;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Referer: https://gitaccuacnz2-my.sharepoint.com/personal/mail_finderacg_com/_layouts/15/onedrive.aspx?.......' -H 'Cookie: CCSInfo=NS8yOS8yMDIwIDEwOjE1OjE0IEFNC/.....; FeatureOverrides_enableFeatures=; FeatureOverrides_disableFeatures=' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: iframe' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: same-origin' --output file.extension

同时这个方法也适合文件夹下载,只不过前缀是 xxxxx-mediap.svc.ms ,其中xxxxx是地区代号,不同的下载链接所指向的地区不同,具体看情况,这里就不再赘述。

 类似资料: