Just want to ftp/scp file from command line
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.
-
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?
-
... 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.
-
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”
-
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
-
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?
-
The Get Folder Items API endpoint returns the collection of items in a given folder, including their names and IDs.
-
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.
-
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
-
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
-
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.txtNothing 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.txtAny help please?
-
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"}```
-
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
Please sign in to leave a comment.
Comments
18 comments