开源地址:LxnChan/OneDrive-Unofficial-CLI
这是一个第三方的OneDrive命令行工具,基于之前使用的未知来源的闭源OneDrive上传工具重构并添加诸多实用功能。
注意:本工具不支持世纪互联版Office 365及OneDrive for Business。
如何获取 前往Github Release 页面获取经过完整测试并预编译的二进制文件 或者你也可以自行编译,代码编写的环境是Windows 11、GoVersion 1.25.3。1 2 3 git clone https://github.com/LxnChan/OneDrive-Unofficial-CLI.git cd onedriveclibuild.bat
必要参数说明 user-agent:User-Agent 请求标头是一个特征字符串,使得服务器和对等网络能够识别发出请求的用户代理的应用程序、操作系统、供应商或版本信息proxy:代理服务器地址,如果你的网络不能够直接或较好的连接到OneDrive网络,可以使用代理服务器client-id:在Microsoft Graph API体系下代表一个客户端应用,使Microsoft API侧知道接口调用方及其权限细节tenant:租户名,可选common(所有用户)、consumers(Microsoft个人账户)或具体指定的租户ID,默认情况下使用common即可覆盖所有场景chunk-size(块大小)和threads(线程数):将上传或下载的数据分块多线程处理,块大小当前版本默认10MB、线程数默认为2。依据网络环境和磁盘IO性能调整这两个参数也许 有助于提升吞吐性能创建自己的ClientID和应用程序端点 尽管本程序预置了一个应用程序端点,但仍建议您自行申请一个ClientID。使用公用ClientID也许会造成数据泄露或其他问题,由此产生的任何问题与作者无关 。
打开Azure Portal ,按照屏幕提示选择企业账户或个人账户登录 前往Microsoft Entra ID 选择“添加”-“应用注册” 按照提示完成应用程序注册 导航到“管理”-“Authentication (Preview)”,勾选“允许公共客户端流”,下方点击保存 导航到“API权限”,添加如下权限:1 email offline_access openid profile user.read Files.ReadWrite.All
导航到“概述”,将“应用程序(客户端) ID”后面的值即为你自己的client-id值;下方的“目录(租户) ID”即为你的tenant值 Usage 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 onedrivecli - OneDrive CLI by LxnChan https://lxnchan.cn Usage: onedrivecli [--config=<PATH>] [--user-agent=<UA>] [--proxy=<MODE>] [--verbose=<true|false>] <command> [options] Commands: login logout status list upload download Parameters: Global: --config=<PATH> Config file path. Default: ./config.json next to the executable. On Linux, also tries /etc/odc/config.json --user-agent=<UA> Set User-Agent for all requests and persist to config.json --proxy=<MODE> Proxy: system/none or http(s)://host:port or host:port (will persist to config.json) --verbose=<true|false> Enable verbose output login: --client-id=<ID> Azure app (public client) client ID (default: built-in) --tenant=<TENANT> common/consumers/organizations or a specific tenant ID (default: common) --scopes=<SCOPES> Space or comma separated scopes (default: offline_access User.Read Files.ReadWrite.All) list: --path=<REMOTE_PATH> Remote directory path (default: root) upload: --local=<LOCAL_PATH> Local file or folder path --remote=<REMOTE_PATH> Remote target path --chunk-size=<SIZE> Chunk size (5MiB-60MiB, default: 10MiB) --threads=<N> Threads (default: 2) download: --remote=<REMOTE_PATH> Remote file or folder path --local=<LOCAL_PATH> Local target path (optional for folders) --chunk-size=<SIZE> Chunk size (5MiB-60MiB, default: 10MiB) --threads=<N> Threads (default: 2) Examples: onedrivecli --config=./config.json status onedrivecli --user-agent="MyApp/1.0" --proxy=system --verbose=true login --client-id=<APP_CLIENT_ID> onedrivecli status onedrivecli list --path=/Documents onedrivecli upload --local=./a.txt --remote=/Documents/a.txt onedrivecli download --remote=/Documents/a.txt --local=./a.txt