You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用pCloud API下载文件遇文件描述符错误,求正确方法

如何通过curl正确调用pCloud API下载文件

问题原因

你遇到的Invalid or closed file descriptor错误,是因为pCloud返回的文件描述符fd是绑定在单个HTTP会话上的。而curl每次单独发起的请求都是独立会话,第二次请求无法复用第一次的会话上下文,所以之前获取的fd会被判定为无效。

正确下载方法

方法一:直接使用download接口(推荐,最简单)

无需调用file_open/file_read,直接用download接口即可完成文件下载,支持通过文件路径或fileid指定目标文件:

# 通过文件路径下载
curl "https://api.pcloud.com/download?access_token=$permtok&path=/foo.txt" -o foo.txt

# 通过fileid下载(可从listfolder或file_open接口获取)
curl "https://api.pcloud.com/download?access_token=$permtok&fileid=1234567890" -o foo.txt

方法二:复用会话调用file_open+file_read(适合特殊场景)

如果必须使用file_open和file_read流程,需要让curl保持同一个会话,通过cookie保存会话上下文:

  • 执行file_open并保存会话cookie:
curl "https://api.pcloud.com/file_open?access_token=$permtok&path=/foo.txt&flags=0x0040" --cookie-jar pcloud_session.txt
  • 复用会话获取文件大小:
curl "https://api.pcloud.com/file_size?access_token=$permtok&fd=1" --cookie pcloud_session.txt
  • 复用会话读取文件内容(替换文件大小数值为实际获取到的大小):
curl "https://api.pcloud.com/file_read?access_token=$permtok&fd=1&count=文件大小数值" --cookie pcloud_session.txt -o foo.txt

方法三:通过file_info获取参数后下载

先调用file_info接口获取文件的fileid和大小,再用file_read下载:

  • 获取文件信息:
file_info=$(curl "https://api.pcloud.com/file_info?access_token=$permtok&path=/foo.txt")
fileid=$(echo "$file_info" | jq -r '.fileid')
filesize=$(echo "$file_info" | jq -r '.size')
  • 用file_read下载:
curl "https://api.pcloud.com/file_read?access_token=$permtok&fileid=$fileid&count=$filesize" -o foo.txt

内容的提问来源于stack exchange,提问作者antonio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 20:15:43