Automatic Upload Script for PEK/XLA swap

This script uploads the contents of the ~/peakecoin and ~/Scala directories to the PeakeCoin FTP server under the /xlaswap directory.

I’ve been working a lot on the @Peakecoin project. I appreciate everyone that has been patient with me. It’s not easy doing the solo mission.

📜 Script: ftp_upload.py

import os
from ftplib import FTP

# FTP credentials
FTP_HOST = "ftp.geocities.ws"
FTP_USER = ""
FTP_PASS = "P"

# Directories to upload
DIRECTORIES_TO_UPLOAD = {
    "peakecoin": os.path.expanduser("~/peakecoin"),
    "Scala": os.path.expanduser("~/Scala"),
}

# FTP Base Directory
FTP_TARGET_DIR = "/xlaswap"

def ensure_ftp_directory(ftp, path):
    """Ensure that the directory exists on the FTP server."""
    directories = path.strip("/").split("/")
    current_path = ""
    for directory in directories:
        current_path += f"/{directory}"
        try:
            ftp.cwd(current_path)
        except:
            try:
                ftp.mkd(current_path)
                print(f"Created directory: {current_path}")
                ftp.cwd(current_path)
            except Exception as e:
                print(f"Error creating directory {current_path}: {e}")
                raise

def upload_directory(ftp, local_dir, ftp_dir):
    """Upload the contents of a local directory to the FTP server."""
    ensure_ftp_directory(ftp, ftp_dir)

    for item in os.listdir(local_dir):
        local_path = os.path.join(local_dir, item)
        if os.path.isfile(local_path):
            print(f"Uploading file: {item}")
            with open(local_path, "rb") as file:
                ftp.storbinary(f"STOR {item}", file)
        elif os.path.isdir(local_path):
            print(f"Creating and uploading directory: {item}")
            upload_directory(ftp, local_path, f"{ftp_dir}/{item}")

def main():
    """Main function to upload directories to FTP."""
    ftp = FTP(FTP_HOST)
    ftp.login(FTP_USER, FTP_PASS)
    ftp.set_pasv(True)  # Enable passive mode

    for folder_name, local_dir in DIRECTORIES_TO_UPLOAD.items():
        print(f"Uploading {local_dir} to {FTP_TARGET_DIR}/{folder_name} on the FTP server...")
        upload_directory(ftp, local_dir, f"{FTP_TARGET_DIR}/{folder_name}")

    ftp.quit()
    print("All uploads complete.")

if __name__ == "__main__":
    main()  _This report was published via Actifit app ([Android](https://bit.ly/actifit-app) | [iOS](https://bit.ly/actifit-ios)). Check out the original version [here on actifit.io](https://actifit.io/@strangedad/actifit-strangedad-20250221t033121740z)_  <img src="https://cdn.steemitimages.com/DQmXv9QWiAYiLCSr3sKxVzUJVrgin3ZZWM2CExEo3fd5GUS/sep3.png" />           <img src="https://actifit.s3.us-east-1.amazonaws.com/ACTIVITYDATE.png" />               19/02/2025              <img src="https://cdn.steemitimages.com/DQmRgAoqi4vUVymaro8hXdRraNX6LHkXhMRBZxEo5vVWXDN/ACTIVITYCOUNT.png" />               5864                <img src="https://cdn.steemitimages.com/DQmZ6ZT8VaEpaDzB16qZzK8omffbWUpEpe4BkJkMXmN3xrF/ACTIVITYTYPE.png" />                Daily Activity, Gym, Walking    <img src="https://cdn.steemitimages.com/DQmNp6YwAm2qwquALZw8PdcovDorwaBSFuxQ38TrYziGT6b/A-20.png" /><img src="https://cdn.steemitimages.com/DQmQqfpSmcQtfrHAtzfBtVccXwUL9vKNgZJ2j93m8WNjizw/l5.png" /><img src="https://cdn.steemitimages.com/DQmbWy8KzKT1UvCvznUTaFPw6wBUcyLtBT5XL9wdbB7Hfmn/l6.png" />