Tuesday 14 May 2013

another (pyrax) way to upload local folder to Rackspace CloudFiles

Other possible ways (I'm sure there is more):

1) curl, httpie http://docs.rackspace.com/files/api/v1/cf-devguide/content/Authentication-d1e639.html

2) bash script (not tested by me) - http://blog.chmouel.com/2010/06/09/upload-to-rackspace-cloud-files-in-a-shell-script/

3) sftp-cloudfs (not tested by me) - http://www.cyberciti.biz/faq/rackspace-openstack-cloud-upload-files-using-sftp-cloudfs-proxy/    ||   https://github.com/Memset/sftpcloudfs

4) OpenStack swift client (not tested by me) - http://goodsquishy.com/2012/08/rackspace-cloud-files-from-the-command-line/

5) turbolift - https://github.com/cloudnull/turbolift

I'm going to use pyrax in this exercise which Rackspace's SDK for python - http://docs.rackspace.com/sdks/guide/content/python.html

Code for my script is available here (I'm not responsible for any data loss while using this script) - https://github.com/marcinrozanski/api/blob/master/upload_folder.py

It assumes you've got credentials file in the following format:

$ cat ~/.rackspace_cloud_credentials
[rackspace_cloud]
username = your_username
api_key = your_API_key
$

Let's say we've got a local folder called "upload_test" with three text files.

$ ls -altr upload_test/
total 24
-rw-r--r--  1 marcin  staff    9 14 May 21:19 file1.txt
-rw-r--r--  1 marcin  staff    9 14 May 21:20 file2.txt
-rw-r--r--  1 marcin  staff    9 14 May 21:20 file3.txt
drwxr-xr-x  5 marcin  staff  170 14 May 22:14 .
drwxr-xr-x  7 marcin  staff  238 14 May 23:12 ..
$
$ cat upload_test/file*.txt 
test 123
test 123
test 123

We want to upload that folder to CloudFiles as container called "cont_test1".

$ python upload_folder.py
Enter container name: cont_test1
Enter folder to upload: upload_test
Beginning Folder Uplaod
Total bytes to upload: 27
Progress: 0.00%
Progress: 33.33%
Progress: 100.00%

Upload Complete.
$




No comments: