Skip to main content

Primitive Ctrl - Remote control of your phone's Primitive FTPd Android SFTP server and optionally Tailscale VPN.

Project description

[!WARNING] This repository works with both the original and the forked version of the Primitive FTPd Android SFTP server!

Primitive Ctrl

Remote control of your phone's Primitive FTPd Android SFTP server and optionally Tailscale VPN.

Though Primitive FTPd consumes minimal power when it is not used, remote start/stop can be usefull for zeroconf (DNS-SD). Android doesn't reply DSN-SD queries when the screen is off, but Android announces the new service when the Primitive FTPd server starts up. So SFTP clients can/should capture and cache the announcement at Primitive FTPd server startup to connect to a phone through zeroconf even when the screen is off.

But in case of Tailscale, it is a real battery and mobile network data drain when not used, remote start/stop is de facto very useful.

With the help of this script you can sync your phone with eg. your home NAS server whereever your phone is on a WiFi network - or even on cellular. Your phone doesn't have to be on the same LAN to make zeroconf working when you have alternative access through VPN.

See my other project, https://github.com/lmagyar/prim-sync, for bidirectional and unidirectional sync over SFTP (multiplatform Python script optimized for the Primitive FTPd SFTP server).

See my other project, https://github.com/lmagyar/prim-batch, for batch execution of prim-ctrl and prim-sync commands.

Note: These are my first ever Python projects, any comments on how to make them better are appreciated.

Features

  • Remote start/stop of Primitive FTPd Android SFTP server and optionally Tailscale VPN
  • Using VPN on cellular can be refused
  • Backup states before starting them, restore when stopping (ie. they won't be stopped if they were running before the script were asked to start them)

Installation

You need to install:

Optionally you can install:

Optionally, if you want to edit or even contribute to the source, you also need to install:

Configuration

Automate

Primitive FTPd

  • Configuration tab
    • UI
      • Show notification to start/stop server(s): disable - this is necessary to determine whether Primitive FTPd is running on the phone or not, because the Automate flow determines whether the server is started with checking the existence of it's notification, and if the notification is always shown, that would make it false positive; please use another way, eg. a Quick Settings Tile to start/stop the server manually

Tailscale VPN (optional)

Follow Tailscale's instructions on how to configure Tailscale VPN on your phone and laptop.

For more details see: https://login.tailscale.com/start

Tailscale Funnel (optional)

You can configure Tailscale Funnel on your laptop (for incoming connections to this script's webhooks from the internet). Until the Tailscale VPN is up on the phone, the phone can't send information directly to your laptop, to this script's webhooks. But Tailscale Funnel makes it possible to access a Tailscale VPN connected device's services from the wider internet.

For more details see: https://tailscale.com/kb/1223/funnel

An example Tailscale Funnel config command for this script is: tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345"

Usage

If you decide to use this script, I suggest to configure Tailscale VPN and Tailscale Funnel, this will provide the most functionality.

Without any VPN, the script will start and stop the Primitive FTPd app on your phone making a best effort and assumes the phone is on the same LAN (ie. zeroconf works). This is fine if you start the script manually and your phone is with you.

But if the script runs scheduled, we can't be sure whether the phone is on WiFi, is on the same WiFi as your laptop: it is better to configure the VPN and Funnel. And I suggest to use the backup and restore functionality also, in this case a scheduled script will not interfere with a manually started Primitive FTPd or VPN, you won't notice the synchronization is running while you are doing something else on the phone with the Primitive FTPd or the VPN.

Notes:

  • Even when -b option is not used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script

Some example

Unix
prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r ${PREV_STATE}
Windows
prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i start -b
prim-ctrl Automate youraccount@gmail.com "SOME MANUFACTURER XXXX" automate your-phone-pftpd --tailscale tailxxxx.ts.net your-phone 2222 --funnel your-laptop 12345 /prim-ctrl 8443 -t -i stop -r !PREV_STATE!

Options

usage: prim-ctrl Automate [-h] [-i {test,start,stop}] [-t] [-s] [--debug] [--tailscale tailnet remote-machine-name sftp-port] [--funnel local-machine-name local-port local-path external-port] [-ac] [-b] [-r STATE]
                          automate-account automate-device automate-tokenfile server-name

Remote control of your phone's Primitive FTPd and optionally Tailscale app statuses via the Automate app, for more details see https://github.com/lmagyar/prim-ctrl

Note: you must install Automate app on your phone, download prim-ctrl flow into it, and configure your Google account in the flow to receive messages (see the project's GitHub page for more details)
Note: optionally if your phone is not accessible on local network but your laptop is part of the Tailscale VPN then Tailscale VPN can be started on the phone
Note: optionally if your laptop is accessible through Tailscale Funnel then VPN on cellular can be refused and app statuses on the phone can be backed up and restored

Output: even when -b option is not used, the script will output 'connected=(local|remote)', what you can use to determine whether to use -a option for the prim-sync script

positional arguments:
  automate-account                 your Google account email you set up in the Automate flow's first Set variable block's Value field
  automate-device                  the device name you can see at the Automate flow's Cloud receive block's This device field
  automate-tokenfile               filename containing Automates's Secret that located under your .secrets folder
                                   (generated on https://llamalab.com/automate/cloud, use the same Google account you set up on the Cloud receive block)
  server-name                      the Servername configuration option from Primitive FTPd app

options:
  -h, --help                       show this help message and exit
  -i {test,start,stop}, --intent {test,start,stop}
                                   what to do with the apps, default: test

logging:
  -t, --timestamp                  prefix each message with an UTC timestamp
  -s, --silent                     only errors printed
  --debug                          use debug level logging and add stack trace for exceptions, disables the --silent and enables the --timestamp options

VPN:
  To use --tailscale option you must install Tailscale and configure Tailscale VPN on your phone and your laptop
  To use --funnel option you must configure Tailscale Funnel on your laptop for prim-ctrl's local webhook to accept responses from the Automate app
     (eg.: tailscale funnel --bg --https=8443 --set-path=/prim-ctrl "http://127.0.0.1:12345")
  Note: --funnel, --backup-state and --restore-state options can be used only when --tailscale is used
  Note: --backup-state is accurate only, when --funnel is used
  Note: --accept-cellular option can be used only when --funnel is used

  --tailscale tailnet remote-machine-name sftp-port
                                   tailnet:             your Tailscale tailnet name (eg. tailxxxx.ts.net)
                                   remote-machine-name: your phone's name within your tailnet (just the name, without the tailnet)
                                   sftp-port:           Primitive FTPd's sftp port
  --funnel local-machine-name local-port local-path external-port
                                   local-machine-name:  your laptop's name within your tailnet (just the name, without the tailnet)
                                   local-port:          12345 - if you used the example tailscale funnel command above (the local webhook will be started on this port)
                                   local-path:          /prim-ctrl - if you used the example tailscale funnel command above
                                   external-port:       8443 - if you used the example tailscale funnel command above
  -ac, --accept-cellular           in case of start, if WiFi is not connected, don't return error, but start VPN up
  -b, --backup-state               in case of start, backup current state to stdout as single string (in case of an error, it will try to restore the original state but will not write it to stdout)
  -r STATE, --restore-state STATE  in case of stop, restore previous state from STATE (use -b to get a valid STATE string)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prim_ctrl-0.3.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

prim_ctrl-0.3.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

Details for the file prim_ctrl-0.3.0.tar.gz.

File metadata

  • Download URL: prim_ctrl-0.3.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for prim_ctrl-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d5f1d6a256e438bef4f8a922a3fe40a686e64d30307d17463cb7b91d6f9bc2a1
MD5 db8c4795beabc9af635c496c4d1614f7
BLAKE2b-256 92e96adafa59d97d3ed8a4ef44950ff519ebecc61ca43af158b70571fd8e936e

See more details on using hashes here.

File details

Details for the file prim_ctrl-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: prim_ctrl-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Windows/11

File hashes

Hashes for prim_ctrl-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17116d71c150c6bf5c7fc69454a4d1142e43a159f5cf0dda2fa064dbf3162a67
MD5 9e6d4b1b5564052f57818c20a767cae8
BLAKE2b-256 a022b27e0e89dc2c5e084a6d43e74cfb1e0f15a54e769872fbb4593f61364622

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page