# HG changeset patch # User Laman # Date 2019-05-05 13:01:34 # Node ID 6c4fa1df8adde5042d070fae6467390055e6186b # Parent dd45e200a0dcc2c01eee3a8cb96da9c2120da7e0 uploading to FTP diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -2,3 +2,4 @@ ^\.idea/ ^images/ ^config.json$ +ftp.json$ diff --git a/exp/kerokero/ftp.py b/exp/kerokero/ftp.py new file mode 100644 --- /dev/null +++ b/exp/kerokero/ftp.py @@ -0,0 +1,22 @@ +import os +import json +import ftplib +import logging as log + +thisDir=os.path.dirname(__file__) +with open(os.path.join(thisDir,"ftp.json")) as f: + cfg=json.load(f) + + +def push(path): + ftp=ftplib.FTP() + ftp.connect(cfg["host"],cfg["port"]) + ftp.login(cfg["user"],cfg["password"]) + + filename=os.path.basename(path) + + log.info("uploading %s",path) + with open(path,mode="rb") as f: + ftp.storbinary("STOR "+filename,f) + + ftp.close()