Skip to content

Instantly share code, notes, and snippets.

@FernandoCelmer
Created December 15, 2022 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FernandoCelmer/33a6cb5560be575a569ed272f4eea041 to your computer and use it in GitHub Desktop.
Save FernandoCelmer/33a6cb5560be575a569ed272f4eea041 to your computer and use it in GitHub Desktop.
"""
Command:
python update.py template/core core
Args:
First argument -> Local Path
Second argument -> Host Path
Requirements:
pip install python-dotenv
"""
import sys
import ftplib
from os import listdir, environ
from os.path import isfile, join
from dotenv import load_dotenv
load_dotenv()
ftp_host = environ.get("HOST")
ftp_username = environ.get("USERNAME")
ftp_password = environ.get("PASSWORD")
base_path = sys.argv[1] if sys.argv[1:] else ''
base_host = sys.argv[2] if sys.argv[2:] else ''
def ftp_connect():
session = ftplib.FTP(ftp_host, ftp_username, ftp_password)
session.cwd(f"/domains/{ftp_host}/public_html/{base_host}")
return session
def ftp_run():
files = [f for f in listdir(base_path) if isfile(join(base_path, f))]
for item in files:
print(f"FILE: {item}")
file = open(f'{base_path}/{item}','rb')
ftp_connect().storbinary(f'STOR {item}', file)
if __name__ == "__main__":
ftp_run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment