Created
September 24, 2013 12:33
-
-
Save insom/6684049 to your computer and use it in GitHub Desktop.
Git Annex FTP backend, particularly for iWeb FTP (create a space called "Annex" and include your username and password in the source to use, for now).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# git config annex.ftp-hook = "/usr/local/bin/git-annex-ftp.py" | |
# git annex initremote iwebftp type=hook hooktype=ftp encryption=none | |
from ftplib import FTP | |
import os | |
f = FTP('prefix.iweb-storage.com', 'prefix-admin', 'password') | |
f.set_pasv(True) | |
cmd = os.environ.get('ANNEX_ACTION') | |
prefix = 'Annex' | |
h1 = os.environ.get('ANNEX_HASH_1') | |
h2 = os.environ.get('ANNEX_HASH_2') | |
key = os.environ.get('ANNEX_KEY') | |
file_ = os.environ.get('ANNEX_FILE') | |
path = "/%s/%s" % (prefix, h1) | |
if cmd == 'store': | |
try: | |
f.mkd(path) | |
f.delete("%s/%s" % (path, key)) | |
except: | |
pass | |
f.storbinary("STOR %s/%s" % (path, key), open(file_, 'rb')) | |
elif cmd == 'retrieve': | |
fi = open(file_, 'wb') | |
f.retrbinary("RETR %s/%s" % (path, key), fi.write) | |
elif cmd == 'remove': | |
f.delete("%s/%s" % (path, key)) | |
elif cmd == 'checkpresent': | |
f.voidcmd('TYPE I') | |
try: | |
if f.size("%s/%s" % (path, key)): | |
print key | |
except: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing the script! I've forked it and added some command line flags to avoid any harcoded connection parameter, see em-/8139438, which is what I'm using it right now.
Would you be interested in converting this gist in a fully flegged github repo where pull requests can be submitted?
Thanks again!