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.
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.
@Hareem Haque Just use
bash mosso.sh temp
My script only take 1 or 0 argument.
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
Try remove -readable from these lines. It doesn’t do anything there.
What’s your operating system?
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!
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
Thanks for the script!
Hi,
Great - Thanks.
Also see http://jonsview.com/projects/cfbackup for a ruby way of doing this.
I get the invalid predicate error on Debian Linux too…