I’ve written a little Python script that may be helpful to other seedbox users. My method for getting the files from the server to my local computer was:

1. cd to where my downloads live
2. sftp in to the server
3. cd to /where/my/server/files/live
4. get -r “file I want to download”

Not too hard, but I’d been wanting an easier way, just never got around to it, until this weekend.

Now, it is simply

$ seedbox.py

Simply copy the script below to sudo cp seedbox.py /usr/local/bin after running chmod +x on the file.

Requirements

The only requirements are that you’re running Linux and have Python3 installed, and you’re using SSH Key-Based Authentication to login to the server.

Usage

The script will login in to the server directory where your downloads live, then show you the last 50 downloads in reverse order (most recent at the bottom), you select a number between 0 and 49, the file / directory will be downloaded to what you chose in dest_dir/YYYY-MM-DD, then your file manager will be opened in that directory.

TODO

I’ll probably run a loop to allow multiple downloads. At the moment, it exits after one download. Maybe allow a range of downloads (0 to 9). Not sure yet.

Screenshot

Here’s how it looks with some test files, green text show which files have already been downloaded:

script screenshot

The Script

#!/usr/bin/python3

#=================================
# Below generated by GNU RCS
#=================================
# $Author: simon $
# $Revision: 1.11 $
# $Date: 2023/02/13 12:01:25 $
#=================================

import os
import sys
import subprocess as sp
import shlex
from pathlib import Path
from datetime import datetime
from termcolor import colored

folder = str(datetime.now().date())

login = 'you@serveraddress'
src_dir = '/server/path/to/files/'
dest_dir = Path(f'/home/yourname/incoming/{folder}')

if not Path.exists(dest_dir):
    Path.mkdir(dest_dir)

p = sp.Popen(['ssh', login, 'ls -t files'],
               stdin=sp.PIPE, stdout=sp.PIPE, text=True)

# Remove trailing newlines
files = [x.rstrip() for x in p.stdout.readlines()]

# Show most recently download files first
for i, f in reversed(list(enumerate(files[:50]))):
    if Path.exists(dest_dir / f):
        print(colored(i, attrs=['bold']), colored(f, 'light_green'))
    else:
        print(colored(i, attrs=['bold']), colored(f, 'light_grey'))

try:
    num = int(input('Enter number to download (most recent first): '))
except ValueError:
    sys.exit('No file chosen. Exiting...')

dl = files[num]

file_path = f"{login}:{src_dir}/{shlex.quote(dl)}"

sp.run(['scp', '-r', file_path, str(dest_dir)])

sp.run(["xdg-open", str(dest_dir)])

Any suggestions or comments, feel free to send me an email.