Mac终端从box.com下载.txt文件失败,求正确解决方法
Hey there, let's work through this problem step by step—those empty random-named files are definitely frustrating, but we have solid alternatives to get your .txt files properly downloaded.
Option 1: Use Box's Official CLI (Most Reliable)
Box has an official command-line tool that handles authentication and file operations correctly, so you won't run into empty file issues here.
- Install the CLI via Homebrew (if you don't have Homebrew, you can set it up easily from its official site—it's a huge help for terminal tools):
brew install box-cli - Log in to your Box account (this will open a browser window for you to authorize the CLI):
box login - First, find the ID of the folder holding your .txt files. Start by listing your top-level folders:
box folders:list - Then list the items inside your target folder to grab the file ID(s):
box folders:items <your-folder-id> --type file - Finally, download the specific .txt file, specifying your desired output name to avoid random numbers:
box files:download <your-file-id> --output-path ./my-downloaded-file.txt
Option 2: Use curl with Box API Authentication
If you'd rather skip installing the CLI, you can use curl with a valid access token to pull the file content directly from Box's API.
- Get a temporary access token:
- Head to the Box Developer Console (no need to build a full app—you can generate a temporary token for your personal account right there).
- Copy the generated access token.
- Find your file's ID: In the Box web interface, open the file and check the URL—you'll see something like
https://app.box.com/file/1234567890where1234567890is the file ID. - Run this
curlcommand to download the file, replacing placeholders with your token and file ID:
Thecurl -H "Authorization: Bearer <your-access-token>" https://api.box.com/2.0/files/<your-file-id>/content -o my-file.txt-oflag lets you set the exact filename you want, so no more random number mess!
Option 3: Use a Direct Download Link (No CLI/API Setup)
If you want a simpler approach without terminal authentication hoops:
- In the Box web interface, right-click your .txt file and select Share.
- Create a share link, then click Link Settings and make sure "Allow downloads" is enabled.
- Copy the direct download link (look for an option like "Copy direct link", or add
?download=trueto the end of your regular share link). - Run this
curlcommand in your terminal, replacing the link with yours:
Thecurl -L "<your-direct-download-link>" -o my-file.txt-Lflag tellscurlto follow any redirects, which Box uses to send you the actual file content instead of a web page.
Why Your Previous Attempts Failed
Those empty random-named files happened because you were trying to download the Box web page URL (not the actual file content). Box's file URLs point to a browser interface, not the raw text data—so your terminal was saving the web page source (which might look empty in a .txt viewer). The commands above target the actual file content, so you'll get the full text you need.
内容的提问来源于stack exchange,提问作者Mohamed Elmalah

