Home > Linux, Web > Cloud files uploading script

Cloud files uploading script

March 13th, 2009

This is a very simple linux bash script to help uploading files to mosso cloud files.

Mosso uploading script: Mosso.sh
Updates: Here is a Mac OSX Version (provided by Bryan Rehbein)

You will also need curl .

After you sign up mosso cloud files service, first you need to login your mosso cloud files control panel then navigate to Your Account / API Access, where you will generate your API key. Edit the begin of mosso.sh

API_KEY=YOURAPIKEYHERE 
USER=yourusername 
CONTAINER=bucket

Now change to the directory where you want to upload files. e.g. a wordpress installation:

cd /srv/http/wordpress
bash mosso.sh wp-includes/js/jquery
Uploading wp-includes/js/jquery/jquery.table-hotkeys.js .... done.
Uploading wp-includes/js/jquery/interface.js .... done.
Uploading wp-includes/js/jquery/ui.core.js .... done.
Uploading wp-includes/js/jquery/jquery.color.js .... done.
Uploading wp-includes/js/jquery/ui.tabs.js .... done.
Uploading wp-includes/js/jquery/ui.resizable.js .... done.
Uploading wp-includes/js/jquery/jquery.hotkeys.js .... done.
Uploading wp-includes/js/jquery/ui.sortable.js .... done.
Uploading wp-includes/js/jquery/ui.dialog.js .... done.
Uploading wp-includes/js/jquery/jquery.js .... done.
Uploading wp-includes/js/jquery/ui.draggable.js .... done.
Uploading wp-includes/js/jquery/jquery.form.js .... done.
Uploading wp-includes/js/jquery/suggest.js .... done.
Uploading wp-includes/js/jquery/jquery.schedule.js .... done.
HTTP/1.1 202 Accepted
Date: Sat, 14 Mar 2009 00:06:41 GMT
Server: Apache
X-CDN-URI: http://cdn.cloudfiles.mosso.com/c12345
Content-Length: 0
Content-Type: text/plain; charset=UTF-8

Write down the url on the line begn with X-CDN-URI. This is your mosso CDN url. You can also find this url inside your mosso control panel.

If you want to upload entire current directory, you can execute this script without argument.

Bookmark and Share  
 

Yejun Linux, Web , , , ,

  1. Hareem Haque
    March 20th, 2009 at 22:28 | #1

    I keep getting the following errors.

    root@hslave1:/mnt# bash mosso.sh -readable temp/
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’

    I have PHP5-curl installed..
    Please advise.

    • Yejun
      March 20th, 2009 at 22:59 | #2

      @Hareem Haque Just use

      bash mosso.sh temp

      My script only take 1 or 0 argument.

  2. Hareem Haque
    March 21st, 2009 at 08:19 | #3

    Sorry to bug you. But i followed your instructions. I still get the following error.
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’
    find: invalid predicate `-readable’

    I think the following code might be miffed in some way.

    for f in $(find $LOC -type f -readable -name \*.js); do
    put $f $f application/x-javascript
    done

    • March 21st, 2009 at 13:01 | #4

      Try remove -readable from these lines. It doesn’t do anything there.
      What’s your operating system?

  3. May 19th, 2009 at 18:02 | #5

    Thanks very much for this script. I’m making a few modifications to it for a client who needs to upload a large amount of data to their Cloud Files account.

    Much appreciated!

  4. edjy
    May 21st, 2009 at 09:37 | #6

    Hi Yejun,

    The Mosso.sh script is a good example of how you can use simple shell commands to interact with the Cloud Files’ REST API.

    However, I would like to point out that it isn’t a very efficient way of using Cloud Files. Each cURL invocation is a separate TCP/IP connection to the storage system and each connection will also incur SSL negotiation.

    Granted, if you were uploading a smaller set of large files, this overhead wouldn’t be noticeable since most of the time would be spent doing data transfer. But with a lot of small files (css, javascript, etc), the performance will be lousy.

    I would strongly recommend using one of the Rackspace provided language API’s. The API’s have been designed to re-use the same TCP/IP+SSL connection to the storage system for each file upload/download. It will greatly improve the overall performance.

    Here’s a quick python version of your shell script using the python-cloudfiles API available at http://www.mosso.com/cloudfiles.jsp.

    http://aep.appspot.com/display/cX8vu2rg8GgiH-zxysC6iXexMBA/

    Hope you and your readers find it useful. If you have any questions/comments, feel free to contact me at ej _at_ racklabs dot com

    -ej

  5. Alex
    June 2nd, 2009 at 19:03 | #7

    Thanks for the script!

  6. July 10th, 2009 at 06:27 | #8

    Hi,
    Great - Thanks.
    Also see http://jonsview.com/projects/cfbackup for a ruby way of doing this.

  7. Ryan
    July 16th, 2009 at 15:33 | #9

    I get the invalid predicate error on Debian Linux too…

  1. March 13th, 2009 at 21:36 | #1