Skip to content

Instantly share code, notes, and snippets.

@poingg
Last active December 12, 2015 09:29
Show Gist options
  • Save poingg/4751543 to your computer and use it in GitHub Desktop.
Save poingg/4751543 to your computer and use it in GitHub Desktop.
Simple hack to have a local FTP that allows Skitch to post files to CloudPT
# Edit these only
# Where do you want your files?
MYCUSTOMDOMAIN_URI = 'http://example.com/Skitch'
MYLOCALFOLDER = '/Users/myhomedir/CloudPT/sites/example.com/Skitch'
# Don't touch below
from pyftpdlib import ftpserver
import httplib, time, os
from urlparse import urlparse
u = urlparse(MYCUSTOMDOMAIN_URI)
MY_NETLOC = u.netloc
if u.path == '':
MY_PATH = '/'
else:
MY_PATH = u.path
class MyHandler(ftpserver.FTPHandler):
def on_file_received(self, file):
status = 0
retries = 20
while status != 200 and retries > 0:
conn = httplib.HTTPConnection(u.netloc)
conn.request("HEAD", MY_PATH + "/"+os.path.basename(file))
res = conn.getresponse()
status = res.status
print 'Got status {}'.format(status)
time.sleep(1)
retries -= 1
if retries == 0:
print 'Gave up...'
else:
print 'Donely done!'
def on_incomplete_file_received(self, file):
os.remove(file)
def main():
authorizer = ftpserver.DummyAuthorizer()
authorizer.add_user("skitch", "skitch", MYLOCALFOLDER, perm="elradfmw")
handler = MyHandler
# handler = ftpserver.FTPHandler
handler.authorizer = authorizer
address = ("127.0.0.1", 2121)
ftpd = ftpserver.FTPServer(address, handler)
ftpd.serve_forever()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment