Automatic Upload Script for PEK/XLA swap

in Actifityesterday

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() <br/> _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)_ <br/> <br><img src="https://cdn.steemitimages.com/DQmXv9QWiAYiLCSr3sKxVzUJVrgin3ZZWM2CExEo3fd5GUS/sep3.png"><br><table>    <tr>        <img src="https://actifit.s3.us-east-1.amazonaws.com/ACTIVITYDATE.png"> </tr>   <tr>        <div class="text-center"><b>19/02/2025</b></div>    </tr></table><table>    <tr>        <img src="https://cdn.steemitimages.com/DQmRgAoqi4vUVymaro8hXdRraNX6LHkXhMRBZxEo5vVWXDN/ACTIVITYCOUNT.png"> </tr>   <tr>        <div class="text-center"><b>5864</b></div>  </tr></table><table>    <tr>        <img src="https://cdn.steemitimages.com/DQmZ6ZT8VaEpaDzB16qZzK8omffbWUpEpe4BkJkMXmN3xrF/ACTIVITYTYPE.png">  </tr>   <tr>        <div class="text-center"><pre><b>Daily Activity, Gym, Walking</b></div></pre></div> </tr></table><div class="text-center"><img src="https://cdn.steemitimages.com/DQmNp6YwAm2qwquALZw8PdcovDorwaBSFuxQ38TrYziGT6b/A-20.png"><a href="https://bit.ly/actifit-app"><img src="https://cdn.steemitimages.com/DQmQqfpSmcQtfrHAtzfBtVccXwUL9vKNgZJ2j93m8WNjizw/l5.png"></a><a href="https://bit.ly/actifit-ios"><img src="https://cdn.steemitimages.com/DQmbWy8KzKT1UvCvznUTaFPw6wBUcyLtBT5XL9wdbB7Hfmn/l6.png"></a></div>
Sort:  
Loading...

Congratulations @strangedad! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You received more than 2500 upvotes.
Your next target is to reach 2750 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP