From 3515df9b153e7cdafb3e82ae32e227cd2e745f54 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Mon, 28 Jun 2021 05:26:42 -0500 Subject: [PATCH] Upload files to FTP server after generating snapshots --- .gitlab-ci.yml | 16 +++++++++++++++- scripts/upload.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/upload.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c8f23c64..4a34ebc3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -101,4 +101,18 @@ generate_versions: artifacts: paths: - artifacts - expire_in: 1 day \ No newline at end of file + expire_in: 1 day + +upload: + stage: upload + tags: + - linux + image: python + interruptible: true + script: + - cd artifacts + - python ../scripts/upload.py + only: + - master + - tags + - schedules \ No newline at end of file diff --git a/scripts/upload.py b/scripts/upload.py new file mode 100644 index 00000000..b170412a --- /dev/null +++ b/scripts/upload.py @@ -0,0 +1,33 @@ +#! /usr/bin/env python +import sys +import os +import glob +import ftplib + +transferred=0 + +def callback(progress): + global transferred + transferred = transferred+len(progress) + print("Uploaded {}".format(convert_bytes(transferred),)) + +ftp_server = os.environ.get("FTP_SERVER") or sys.argv[1] +ftp_username = os.environ.get("FTP_USERNAME") or sys.argv[2] +ftp_password = os.environ.get("FTP_PASSWORD") or sys.argv[3] + +print("Uploading files to the TWBlue server...") +print("Connecting to %s" % (ftp_server,)) +connection = ftplib.FTP(ftp_server) +print("Connected to FTP server {}".format(ftp_server,)) +connection.login(user=ftp_username, passwd=ftp_password) +print("Logged in successfully") +connection.cwd("web/pubs") +files = glob.glob("*.zip")+glob.glob("*.exe") +print("These files will be uploaded into the version folder: {}".format(files,)) +for file in files: + transferred = 0 + print("Uploading {}".format(file,)) + with open(file, "rb") as f: + connection.storbinary('STOR %s' % file, f, callback=callback, blocksize=1024*1024) +print("Upload completed. exiting...") +connection.quit() \ No newline at end of file