当前位置: 首页 > news >正文

通过vps命令行向dropbox上传文件

vps空间比较小,分段下载大文件

# Part 1: 0 to 1GB-1
curl -r 0-1073741823 -o part1 https://example.com/yourfile.iso# Part 2: 1GB to 2GB-1
curl -r 1073741824-2147483647 -o /tmp/part1 https://dn721502.ca.archive.org/0/items/windows-1809/Windows%201809.iso -k# Part 3: 2GB to 3GB-1
curl -r 2147483648-3221225471 -o /tmp/part1 https://dn721502.ca.archive.org/0/items/windows-1809/Windows%201809.iso -k# Part 4: 3GB to end (3.8GB)
curl -r 3221225472- -o /tmp/part1 https://dn721502.ca.archive.org/0/items/windows-1809/Windows%201809.iso -k
import os
import requests
import jsonACCESS_TOKEN = 'token'
LOCAL_FILE = '/tmp/part1'    # e.g. '/tmp/part1'
DROPBOX_PATH = '/filename.ext'     # final path in Dropbox (with filename)
CHUNK_SIZE = 150 * 1024 * 1024            # 150 MBdef upload_large_file():file_size = os.path.getsize(LOCAL_FILE)print(f'[INFO] File size: {file_size} bytes')with open(LOCAL_FILE, 'rb') as f:# Step 1: start upload sessiontry:chunk = f.read(CHUNK_SIZE)print(f'[INFO] Starting upload session with first chunk size: {len(chunk)} bytes')headers = {"Authorization": f"Bearer {ACCESS_TOKEN}","Content-Type": "application/octet-stream",}url = "https://content.dropboxapi.com/2/files/upload_session/start"response = requests.post(url, headers=headers, data=chunk)response.raise_for_status()session_id = response.json()['session_id']print(f'[SUCCESS] Upload session started. Session ID: {session_id}')except requests.exceptions.RequestException as e:print(f'[ERROR] Failed to start upload session: {e}')print(f'[DEBUG] Response content: {getattr(e.response, "content", None)}')returnoffset = len(chunk)# Step 2: append chunkswhile offset < file_size:try:chunk = f.read(CHUNK_SIZE)if not chunk:print('[INFO] No more data to read for append.')breakprint(f'[INFO] Appending chunk at offset {offset}, size: {len(chunk)} bytes')headers = {"Authorization": f"Bearer {ACCESS_TOKEN}","Content-Type": "application/octet-stream","Dropbox-API-Arg": json.dumps({"cursor": {"session_id": session_id,"offset": offset},"close": False})}url = "https://content.dropboxapi.com/2/files/upload_session/append_v2"response = requests.post(url, headers=headers, data=chunk)response.raise_for_status()print(f'[SUCCESS] Chunk appended at offset {offset}')offset += len(chunk)except requests.exceptions.RequestException as e:print(f'[ERROR] Failed to append chunk at offset {offset}: {e}')print(f'[DEBUG] Response content: {getattr(e.response, "content", None)}')return# Step 3: finish upload sessiontry:print(f'[INFO] Finishing upload session at offset {offset}')headers = {"Authorization": f"Bearer {ACCESS_TOKEN}","Content-Type": "application/octet-stream","Dropbox-API-Arg": json.dumps({"cursor": {"session_id": session_id,"offset": offset},"commit": {"path": DROPBOX_PATH,"mode": "add","autorename": True,"mute": False}})}url = "https://content.dropboxapi.com/2/files/upload_session/finish"response = requests.post(url, headers=headers, data=b'')response.raise_for_status()print(f'[SUCCESS] Upload finished. File saved to {DROPBOX_PATH}')print('[INFO] Dropbox API response:')print(response.json())except requests.exceptions.RequestException as e:print(f'[ERROR] Failed to finish upload session: {e}')print(f'[DEBUG] Response content: {getattr(e.response, "content", None)}')if __name__ == '__main__':upload_large_file()

将/tmp/part1上传至/filename.ext

相关文章:

  • lua脚本实战—— Redis并发原子性陷阱
  • 文章记单词 | 第102篇(六级)
  • 深度剖析并发I/O模型select、poll、epoll与IOCP核心机制
  • ”故茗”茶文化网站
  • 【【嵌入式开发 Linux 常用命令系列 19 -- linux top 命令的交互使用介绍】
  • 谢飞机的Java面试奇遇:AIO、BIO、NIO与Netty深度解析
  • 【心海资源】【原创开发】TG,飞机,电报,协议号及直登号转API
  • RK常见系统属性设置/获取命令使用
  • 推进可解释人工智能迈向类人智能讨论总结分享
  • canal实现mysql数据同步
  • python web flask专题-Flask入门指南:从安装到核心功能详解
  • 人脸识别技术合规备案最新政策详解
  • NC IntellisysIQ QP、QPA和QPD QP3 Slave buried slave ON RS232 等通讯接口针脚定义
  • 多语种多场景的的分页详解
  • Linux下MySQL的安装与使用
  • Linux C/C++编程 —— 线程技术总结
  • NGINX如何处理静态文件?你会如何优化静态文件的传输?
  • 1538. 【中山市第十一届信息学邀请赛决赛】互质(different)
  • 从制造到智造:猎板PCB的技术实践与产业价值重构
  • 文章记单词 | 第115篇(六级)
  • 梅州网站建设公司/网站诊断分析
  • 江苏省住房城乡建设厅网站首页/网络广告营销经典案例
  • 用asp做的网站有多少/百度图片搜索引擎
  • 济宁市环保局建设项目审批网站/深圳网站seo公司
  • 昆明做百度网站电话号码/seo和sem的区别
  • 做旅行社网站/百度如何推广产品