Skip to main content
Question

Just want to ftp/scp file from command line

  • May 21, 2025
  • 18 replies
  • 101 views

Forum|alt.badge.img

Hi,

 

So I'm used to transferring files between servers using scp and ftp.  I've never done it with curl though and I didn't immediately see how to do this from online guides I found.  Could anyone post an example of how to do this?  E.g., to get the file TestDoc1.txt in the default directory, https://app.box.com/folder/0.

18 replies

Forum|alt.badge.img

 Here is a cURL example showing how to upload a file to Box.

 

//Upload file
curl https://upload.box.com/api/2.0/files/content \
  -H "Authorization: Bearer ACCESS_TOKEN" -X POST \
  -F attributes='{"name":"example.csv", "parent":{"id":"0"}}' \
  -F file=@example.csv

  


Forum|alt.badge.img

Terrific! Tried it and it worked.  Just need to figure out how to go in the other direction and this thread is solved.  I tried this

 

curl https://download.box.com/api/2.0/files/content \
  -H "Authorization: Bearer ACCESS_TOKEN" -X GET\
  -F attributes='{"name":"example.csv", "parent":{"id":"0"}}' \
  -F file=@example.csv

 

but I got

 

curl: (26) failed creating formpost data

 

Know what the right version is?


Forum|alt.badge.img

... and after a harder look at the API tried this

 

curl https://api.box.com/api/2.0/files/example.csv/content \
  -H "Authorization: Bearer ACCESS_TOKEN" -X GET\
  -F attributes='{"name":"example.csv", "parent":{"id":"0"}}' \
  -F file=@example.csv

and numerous variations thereof.  Still no luck.


Forum|alt.badge.img

 Below is a cURL example showing how to download a file with our API. Within our reference documentation, we have example cURL requests for our API endpoints.

 

 

curl -L https://api.box.com/2.0/files/REPLACE_WITH_FILE_ID/content \
-H "Authorization: Bearer REPLACE_WITH_TOKEN”

 


Forum|alt.badge.img

https://github.com/stedwards/PrintToBox

 

This uses 1 AppUser. Depending on your licensing, this may or may not cost additional money.

The nice thing is once it's set up, you don't have to set it up again and you don't have to maintain tokens.

 

At the moment, it's upload only. I'd like to do a more generic solution like the old Ruby CLI here that

is broken.

https://github.com/IoraHealth/box_cli

 

And I'd like to pull down files as well.

 

FWIW


Forum|alt.badge.img

I tried this command to upload a file and got these error as per the details below:

 

curl https://upload.box.com/api/2.0/files/content \ -H "Authorization: Bearer My-App-Token” -X POST \ -F attributes='{"name":"test.rft", "parent":{"id":"0"}}' \ -F file=@/Users/Sandesh/Desktop/test.rft

 

Error:

No Content Length

 

No Content Length


 

Description: Could not process this request because

there was no Content-Length specified.


curl: (6) Could not resolve host:  -H

curl: (3) [globbing] nested brace in column 115

curl: (6) Could not resolve host: Bearer

curl: (6) Could not resolve host: My-App-Token”

curl: (6) Could not resolve host:  -F

curl: (3) [globbing] nested brace in column 41

curl: (6) Could not resolve host:  -F

curl: (6) Could not resolve host: Users

 

I have removed the token from this message.

 

Is there something missing in this command?


Forum|alt.badge.img

How do I get a list of all the file IDs and file names in a folder? Thanks!


Forum|alt.badge.img

 The Get Folder Items API endpoint returns the collection of items in a given folder, including their names and IDs.


Forum|alt.badge.img

I saw you removed the token from the example (as you should). My question is, how did you get that token in the first place? I'm really struggling with automating the token generation, and wondering if I'm missing something simple.


Forum|alt.badge.img

Couchdrop may make this easier for you? You can SCP/SFTP and Rsync to Box. It is easy to setup and will save you time. 

 

An example of scp would be:

scp filename.txt username<@>scp.couchdrop.io:/Box

 

or to pull your file down

 

scp username<@>scp.couchdrop.io:/Box/filename.txt ~/

 

or you can sftp username<@>sftp.couchdrop.io: and use the interactive SFTP shell with your Box storage.


Forum|alt.badge.img

I have the same problem. Do let me know if you had figured out how!


Forum|alt.badge.img

Could you explain or post a link on how to get an "Acess Token"?


Forum|alt.badge.img

To create the token go to https://app.box.com/developers/console then create a new app, custom app, call it something like shell script. Generate a new primary access token, give it an expiry date (or never expire). Then copy that and that is the key that goes after Authorization: Bearer


Forum|alt.badge.img

I was a bit startled not to see Boxs built-in support for FTP/FTPS mentioned here. (Unless I missed something?) Check out https://community.box.com/t5/Upload-and-Download-Files-and/Using-Box-with-FTP-or-FTPS/ta-p/26050 for all the details. 

Hope that helps,

 

Ian


Forum|alt.badge.img

When i tried in Terminal on mac,

 

curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer GdeRrUh3nm8VJCUzd3LEIGyyLWiyR2op" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"0"}}' \
-F file=@test.txt

 

Nothing happened. Do I need to give full path for file?

 

If give it like below file full path like below, then i get error

curl: (26) couldn't open file "/Users/myuser/test.txt"

 like in Terminal

 

curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer GdeRrUh3nm8VJCUzd3LEIGyyLWiyR2op" -X POST \
-F attributes='{"name":"test.txt", "parent":{"id":"0"}}' \
-F file=@/Users/myuser/test.txt

 

Any help please?

 


Forum|alt.badge.img

What exactly needs to go in REPLACE_WITH_FILE_ID?  I've tried a bunch of things like the file name and various codes from the links and the response is always ```{"type":"error","status":404,"code":"not_found","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Not Found","request_id":"af8811ge3jm2otvs"}```

 


Forum|alt.badge.img

Hello, I need this functionality too. Anyone have any luck with a solution?


Forum|alt.badge.img

I mentioned Box’s native FTP support earlier in this thread, but also check out https://rclone.org/box— rclone is very similar to rsync, but for various cloud services. 

Hope that helps!

 

Ian