Join BoxWorks in San Francisco Nov 12-13! Keynotes, product demos, and Box Master Classes. Reserve your spot!

Just want to ftp/scp file from command line

New post

Comments

18 comments

  • Murtza

     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

      

    0
    Comment actions Permalink
  • MattPhillips

    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?

    0
    Comment actions Permalink
  • MattPhillips

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

    0
    Comment actions Permalink
  • Murtza

     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”

     

    0
    Comment actions Permalink
  • Luyseyal

    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

    0
    Comment actions Permalink
  • BTH

    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?

    0
    Comment actions Permalink
  • tommycarstensen

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

    0
    Comment actions Permalink
  • mwiller

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

    0
    Comment actions Permalink
  • pugilist4TBI

    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.

    0
    Comment actions Permalink
  • Barty

    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.

    0
    Comment actions Permalink
  • siyyanki

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

    0
    Comment actions Permalink
  • ndbarret

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

    0
    Comment actions Permalink
  • SecMe

    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

    0
    Comment actions Permalink
  • iancrew

    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

    0
    Comment actions Permalink
  • Prabakar8177

    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?

     

    0
    Comment actions Permalink
  • archmageirvine

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

     

    0
    Comment actions Permalink
  • JeffGrisso

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

    0
    Comment actions Permalink
  • iancrew

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.