Download a folder from box using Terminal Command Line

Highlighted
First-time Contributor

Download a folder from box using Terminal Command Line

To download a file from the terminal I am currently using:

curl -X GET https://api.box.com/2.0/files/FILE_ID/content -H "Authorization: Bearer AUTH_TOKEN" -L >> filename

 

To now download an entire directory, I do:

curl -X GET https://api.box.com/2.0/folders/FOLDER_ID/items -H "Authorization: Bearer AUTH_TOKEN" -L >> output

 I get a JSON file with the list of filenames (incomplete)

 

2 questions:

 

  1. How to download all the files in a directory from the above command?
  2. How to make sure it's complete?

 

1 REPLY 1
Highlighted
Box Employee

Re: Download a folder from box using Terminal Command Line

Hi @hahuja,

 

Let me see if I can provide some context:

 

How to download all the files in a directory from the above command?

As you've seen in your second call, the /items endpoint will provide you with a list of the files and folders within a given folder ID. To keep this on the terminal you can write a small bash script that will pull in the items, look through each, and then make a request to get each of the files (your first call).

 

How to make sure it's complete?

You can use the limit parameter, shown in the API reference, to increase the number of results returned. If you have too many results to return in these instances then you'll have to page through the results (under "related guides" here). In essence you'll download a chunk of the file list, then use a marker (where you left off in the list) to make a second call (and third, etc.) to get the next chunk of results, until it's complete.

 

Hope that helps,

Jon