Just want to ftp/scp file from command line

Highlighted
New Contributor

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.

18 REPLIES 18
Highlighted
Box Employee

Re: Just want to ftp/scp file from command line

@MattPhillips 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

  

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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?

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

... 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.

Highlighted
Box Employee

Re: Just want to ftp/scp file from command line

@MattPhillips 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”

 

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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:

<HTML>

<HEAD>

<TITLE>No Content Length</TITLE>

</HEAD>

 

<BODY BGCOLOR="white" FGCOLOR="black">

<H1>No Content Length</H1>

<HR>

 

<FONT FACE="Helvetica,Arial"><B>

Description: Could not process this request because

there was no Content-Length specified.

</B></FONT>

<HR>

</BODY>

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?

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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

Highlighted
Box Employee

Re: Just want to ftp/scp file from command line

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

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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.

Highlighted
Occasional Contributor

Re: Just want to ftp/scp file from command line

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.

Highlighted
First-time Contributor

Re: Just want to ftp/scp file from command line

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

Highlighted
First-time Contributor

Re: Just want to ftp/scp file from command line

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

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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
Highlighted
Trusted Contributor

Re: Just want to ftp/scp file from command line

I was a bit startled not to see Box’s 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

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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?

 

Highlighted
First-time Contributor

Re: Just want to ftp/scp file from command line

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"}```

 

Highlighted
New Contributor

Re: Just want to ftp/scp file from command line

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

Highlighted
Trusted Contributor

Re: Just want to ftp/scp file from command line

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