Skip to content

Instantly share code, notes, and snippets.

@insom
Created September 24, 2013 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save insom/6684049 to your computer and use it in GitHub Desktop.
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).
#!/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
@em-
Copy link

em- commented Dec 26, 2013

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment