Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # -------------------------------
- # Seedbox
- # -------------------------------
- REMOTE_HOST="" # Remote FTP host
- REMOTE_USER="" # Remote FTP username
- REMOTE_PASSWORD="" # Remote FTP password
- # -------------------------------
- # Variables
- # -------------------------------
- REMOTE_DIR="" # Remote directory or file to sync
- LOCAL_DIR="" # Local directory for syncing
- # -------------------------------
- # qBittorrent
- # -------------------------------
- QB_API_URL="/api/v2" # qBittorrent Web API URL
- QB_USERNAME="" # qBittorrent username
- QB_PASSWORD="" # qBittorrent password
- QB_CATEGORY="" # qBittorrent category for filtering torrents
- # Check if lftp is already running
- if ps aux | grep -v grep | grep -q "lftp"; then
- echo "lftp is already running. Exiting."
- exit 1
- fi
- # -------------------------------
- # Login to qBittorrent API
- # -------------------------------
- echo "Logging in to qBittorrent..."
- QB_COOKIE=$(curl -si -X POST "$QB_API_URL/auth/login" \
- --data-urlencode "username=$QB_USERNAME" \
- --data-urlencode "password=$QB_PASSWORD" | grep -oP 'set-cookie: \K.*SID=.*' | tr -d '\r')
- if [ -z "$QB_COOKIE" ]; then
- echo "Failed to log in to qBittorrent."
- exit 1
- fi
- echo "Login successful."
- # -------------------------------
- # Check for active downloads in qBittorrent
- # -------------------------------
- echo "Checking for active downloads in qBittorrent..."
- RESPONSE=$(curl -s -b "$QB_COOKIE" "$QB_API_URL/torrents/info")
- if [ $? -ne 0 ] || [ -z "$RESPONSE" ]; then
- echo "Failed to fetch torrent info. Exiting."
- exit 1
- fi
- ACTIVE_PATHS=$(echo "$RESPONSE" | jq -r \
- ".[] | select(.state | test(\"downloading|stalledDL\")) | select(.category == \"$QB_CATEGORY\") | .content_path")
- if [ -n "$ACTIVE_PATHS" ]; then
- echo "Active downloads detected. Skipping sync."
- exit 0
- fi
- echo "No active downloads detected. Proceeding with sync."
- # -------------------------------
- # Run lftp to list files and download them if modified since the last sync
- # -------------------------------
- echo "Starting lftp sync for new/updated files..."
- lftp -u "$REMOTE_USER","$REMOTE_PASSWORD" "$REMOTE_HOST" -e "
- set file:use-lock true;
- set xfer:use-temp-file true;
- set xfer:temp-file-name *.lftp
- mirror --continue \
- --parallel=3 \
- $REMOTE_DIR $LOCAL_DIR;
- bye;
- "
- echo "Sync and transfer completed."
Add Comment
Please, Sign In to add comment