DEV Community

Mmm
Mmm

Posted on

Retro File Upload Bot: Automate Legacy File Uploads in Python (No GUI Needed)

Ever had to manually upload 50+ files to a legacy system that requires specific headers, authentication tokens, and strict filename patterns? I did—three times last week while fixing a production pipeline. That’s why I built Retro File Upload Bot: a lightweight Python tool to automate uploads to retro-style web services that reject most modern APIs. It solves the pain of tedious, error-prone manual uploads by handling authentication, headers, and file validation without GUIs or complex dependencies.

Here’s how it works in practice. The bot uses the requests library (included in Python’s standard library for most cases) to send files via POST requests with custom headers. It validates filenames against a regex pattern before uploading to avoid rejected payloads. No fancy web interfaces—just pure CLI automation.

First, install the dependency (if needed):

pip install requests
Enter fullscreen mode Exit fullscreen mode

Then, here’s the core upload function that handles everything:

import re
import requests

def upload_to_retro(file_path, token, base_url):
    # Validate filename (e.g., only alphanumeric + underscores)
    if not re.match(r'^[a-zA-Z0-9_]+\.png$', file_path):
        raise ValueError("Invalid filename format. Must be alphanumeric + underscore + .png")

    # Send file with custom headers
    headers = {
        "X-API-Key": token,
        "Content-Type": "application/octet-stream"
    }
    with open(file_path, "rb") as f:
        response = requests.post(
            f"{base_url}/upload",
            headers=headers,
            data=f,
            timeout=10
        )
    return response.status_code
Enter fullscreen mode Exit fullscreen mode

For quick testing, here’s a minimal usage example:

# Example: Upload a file to a local retro API
upload_to_retro(
    file_path="report.png",
    token="your_api_token_here",
    base_url="https://your-retro-service.com"
)
Enter fullscreen mode Exit fullscreen mode

This script works because retro services often have quirks—like rejecting files with spaces in names or requiring specific headers. By validating filenames upfront and using requests.post with raw binary data, we avoid common pitfalls (e.g., MIME type mismatches). The timeout=10 prevents hanging on slow uploads, and the regex ensures only clean filenames get processed.

Why is this useful? In real-world scenarios, legacy systems (like old internal APIs or test environments) often require manual uploads for compliance or debugging. Retro File Upload Bot cuts hours of repetitive work—especially when you’re dealing with 100+ files daily. It’s also portable: run it on your laptop, CI server, or even a Raspberry Pi without extra setup.

I built this after struggling with a client’s legacy file system that used a non-standard API. The tool’s simplicity (under 50 lines of code) makes it perfect for beginners too—no web frameworks or complex state management. You can tweak the regex or headers easily for different services, but the core pattern works for most retro APIs.

If you're curious about the full script (with error handling, logging, and a config file), grab it here: https://7982180762074.gumroad.com/l/rcgbt

Have you ever automated a similar tedious task? What’s the one file upload you’d automate tomorrow? Share your story below—I’d love to hear it!

Top comments (0)