Ubuntu One has the concept of publishing a file — that is, giving a file in your personal cloud a URL so that anyone can download it, if you tell them the URL — but you can’t currently do that with a whole folder of files. Since that’d be quite a useful thing to be able to do, and it’s not yet supported by U1 itself, I wrote a little script to do it, u1-publish-folder (the script needs you to be on Ubuntu 12.04, which is released next week). Simply do u1-publish-folder /path/to/synced/folder and it’ll give you a URL for the index for that folder; a handy way to get a bunch of files to someone without a U1 account* where they can pick and choose the ones they want (rather than sending them a zip file, or sharing a folder with them).
The way it actually works is to publish all the files in the folder, then create an HTML index file linking to all those published files, then sync and publish the index. So you get a directory listing, like Apache gives you when you browse a folder: List of files in testpublishfolder.
The thing I found nicest about this is working with SyncDaemonTool, the Python U1 controller. Combined with Twisted’s defer.inlineCallbacks stuff, it makes dealing with U1 really easy:
@defer.inlineCallbacks
def dosomething():
sd = SyncDaemonTool()
metadata = yield sd.get_metadata("/home/aquarius/Documents/somefile")
print metadata
Normally, dealing with async stuff is hard, but it’s just dead easy this way; simply throw in a yield and you can write code as if it’s normally synchronous but it’s actually async, so your program doesn’t block while it’s working and you don’t need to invent a zillion “callback” functions (whether they’re anonymous functions or not). I like this.
hi.. thanks for the nice script.. but there is one error:
Examining folder /home/wolf/bla —
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 361, in callback
self._startRunCallbacks(result)
File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 455, in _startRunCallbacks
self._runCallbacks()
File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 542, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 1076, in gotResult
_inlineCallbacks(r, g, deferred)
—
File “/usr/lib/python2.7/dist-packages/twisted/internet/defer.py”, line 1020, in _inlineCallbacks
result = g.send(result)
File “./Desktop/u1-publish-folder”, line 103, in process_folder
publicfiles = yield sd.get_public_files()
exceptions.AttributeError: ‘SyncDaemonTool’ object has no attribute ‘get_public_files’
Do I do something wrong?
Thanks for reply.
Please update this, thanks!
http://askubuntu.com/questions/96499/how-do-i-share-a-folder-to-the-public
Michael,
Ah, good catch: this will likely require Ubuntu 12.04. I’ll update the main post.
Please, report that bug for ubuntu one and upload your patch on the bug report. SO it may get upstream, soon!
I thank you for that, but I only install software (except my own) that is packaged.
varför kan jag inte spela city vill på facebook staden försvinner
Nice script! Makes life easier.
Nonetheless, I’d like to know is there an easy way to stop publishing a folder? Of course I can delete/unpublish the created html index, but the files remain published this way. Is there any other trick than making them unpublished one by one?
Konsta: there isn’t an easy way to unpublish all the files already, but another script to do so (“for file in directory: unpublish(file)”) wouldn’t be too hard
Wow, awesome! Thanks!!!
Is here any way to let the script provide https links in the index file. This to prevent restrictive content scanning on some proxy systems and overall, less snooping on my internet line (Data Retention and so on). I know Ubuntu One supports this, just replace the http with the https afterwards, but it would be nice to have it in one script.
Thanks!!! It’s great!!!
Thank you very much, this is really cool. I see a really cool future for u1