SkillAgentSearch skills...

Tfatool

Tools for managing files with the Toshiba FlashAir wireless SD card

Install / Use

/learn @TadLeonard/Tfatool
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<img align="right" src="_docs/flashair.jpg">

tfatool: Toshiba FlashAir Tool

License PyPI version

This package provides easy access to the Toshiba FlashAir wireless SD card. As a library, tfatool provides an easy-to-use abstraction of the FlashAir API. The package includes two command line utilities: flashair-util gives the user a way of synchronizing/mirroring files and directories between the local filesystem and FlashAir, while flashair-config lets the user configure the the deivce.

Command line usage at a glance

Action | Command
----------------------------------------------------------- | ------------------------------------------------ Monitor FlashAir for new JPEGs, download to ~/Photos | flashair-util -s -d /home/tad/Photos --only-jpg Monitor working dir for new files, upload to FlashAir | flashair-util -s -y up Monitor a local and remote dir for new files, sync them | flashair-util -s -y both Sync down the 10 most recent to a local dir, then quit | flashair-util -S time -d images/new/ Sync up all files created in 1999 and afterwards | flashair-util -S all -t 1999 Sync down files created between Jan 23rd and Jan 26th | flashair-util -S all -t 1-23 -T 01/26 Sync files (up AND down) created this afternoon | flashair-util -S all -t 12:00 -T 16:00 -y both Sync files up created after a very specific date/time | flashair-util -S all -t '2016-1-25 11:38:22' Sync (up and down) 5 most recent files of a certain name | flashair-util -S time -k 'IMG-08.+\.raw' -y both List files on FlashAir created after a certain time | flashair-util -l -t '1-21-2016 8:30:11' Change FlashAir network SSID | flashair-config --wifi-ssid myflashairnetwork Show FlashAir network password & firmware version | flashair-config --show-wifi-key --show-fw-version

Package contents at a glance

  • flashair-util: a command line tool for mirroring and listing files on FlashAir
  • flashair-config: a command line tool for configuring FlashAir
  • tfatool.command: abstraction of FlashAir's command.cgi
  • tfatool.upload: abstraction of FlashAir's upload.cgi
  • tfatool.config: abstraction of FlashAir's config.cgi
  • tfatool.sync: functions for synchronizing local dirs with remote FlashAir dirs

Read the FlashAir documentation for more information about the API tfatool uses.

Usage guide

Using the flashair-util script

Help menu

$ flashair-util -h
usage: flashair-util [-h] [-v] [-l] [-c] [-s] [-S {time,name,all}]
                     [-y {up,down,both}] [-r REMOTE_DIR] [-d LOCAL_DIR] [-j]
                     [-n N_FILES] [-k MATCH_REGEX] [-t EARLIEST_DATE]
                     [-T LATEST_DATE]

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose

Actions:
  -l, --list-files
  -c, --count-files
  -s, --sync-forever    watch for new files in REMOTE_DIR, copy them to
                        LOCAL_DIR (runs until CTRL-C)
  -S {time,name,all}, --sync-once {time,name,all}
                        move files (all or by most recent name/timestamp) from
                        REMOTE_DIR to LOCAL_DIR, then quit

Setup:
  -y {up,down,both}, --sync-direction {up,down,both}
                        'up' to upload, 'down' to download, 'both' for both
                        (default: down)
  -r REMOTE_DIR, --remote-dir REMOTE_DIR
                        FlashAir directory to work with (default:
                        /DCIM/100__TSB)
  -d LOCAL_DIR, --local-dir LOCAL_DIR
                        local directory to work with (default: working dir)

File filters:
  -j, --only-jpg        filter for only JPEG files
  -n N_FILES, --n-files N_FILES
                        Number of files to move in --sync-once mode
  -k MATCH_REGEX, --match-regex MATCH_REGEX
                        filter for files that match the given pattern
  -t EARLIEST_DATE, --earliest-date EARLIEST_DATE
                        work on only files AFTER datetime of any reasonable
                        format such as YYYY, YYYY-MM, MM/DD, HH:mm (today), or
                        'YYYY-MM-DD HH:mm:ss'
  -T LATEST_DATE, --latest-date LATEST_DATE
                        work on only files BEFORE given datetime

Prelude: filtering files by name, creation time

All operations flashair-util carries out (both remote and local) can be restricted to a subset of files with some simple arguments. We can filter by filename and by creation date/time.

Filtering by date and time

Date/times are parsed from the command line in a human-friendly manner. If you pass "1998", it'll be parsed as "1998-01-01 00:00:00". Passing a string like "11/4" or "11-04" will be be seen as "{current year}-11-04 00:00:00".

The -t or --earliest-date option filters for only files AFTER the given date/time. The -T or --latest-date option filters for only files BEFORE the given date/time. You can use -t and -T together to filter for files within a slice of time. Some examples:

  • -T 2015: all files created before 2015
  • -t 18:00: all files created this evening (after 6:00 pm today)
  • -t 2014 -T 2015: all files created in 2014
  • -t 11/4 -T 11/28: all files created between Nov. 4 and Nov 28 of this year
  • -t '2016-4-02 11:30' -T '2016/04/02 13:30': all files created Apr. 2nd between 11:30 am and 2:30 pm.
  • -t 7:00 -T 11:00: all files created this morning

Filtering by filename

Files can also be filtered by their name. The -j or --only-jpg option filters for JPEG files. Filters of greater complexity can be made with the -k/--match-regex option, which matches the filename against a regular expression pattern. Some examples:

  • --match-regex '.+\.raw': match all files ending in .raw
  • -k 'IMG-08.+\.jpg': match all JPEGs starting with IMG-08

Example 1: sync newly created files on FlashAir card

The -s/--sync-forever mode watches for new files. When new files are found, they're synchronized with the specified local or remote directory.

File synchronizing can be done in one of three ways:

  1. Download only (default or chosen with -y down/--sync-direction down)
  2. Upload only (-y up/--sync-direction up)
  3. Bidirectional (-y both/--sync-direction both)

Monitor FlashAir for JPEGs and copy them to path/to/files as they appear.

$ flashair-util -s -d path/to/files --only-jpg
2016-01-22 21:29:12,336 | INFO | main | Syncing files from /DCIM/100__TSB to path/to/files
2016-01-22 21:28:44,035 | INFO | main | Creating directory 'path/to/files'
2016-01-22 21:29:27,412 | INFO | tfatool.sync | Ready to sync new files (39 existing files ignored)

Some time later, a new photo appears in the default remote directory.

2016-01-22 21:30:05,770 | INFO | tfatool.sync | Files to sync:
  IMG_0802.JPG
2016-01-22 21:30:05,770 | INFO | tfatool.sync | Copying remote file IMG_0802.JPG to stuff/IMG_0802.JPG
2016-01-22 21:30:05,771 | INFO | tfatool.sync | Requesting file: http://flashair/DCIM/100__TSB/IMG_0802.JPG
2016-01-22 21:30:05,866 | INFO | tfatool.sync | Wrote IMG_0802.JPG in 1.00 s (4.31 MB, 4.31 MB/s)

Example 2: sync subset of files on FlashAir just once

Sync JPEG files that were created between December 15th, 2015 (at 3:00 pm) and January 12, 2016 with the local stuff/ directory. Notice that files which already exist and match the size in bytes of those on FlashAir are not overwritten.

flashair-util -S all -d stuff/ -j -t '2015-12-15 15:00' -T 2016-01-12
2016-01-22 22:29:02,228 | INFO | main | Syncing files from /DCIM/100__TSB to stuff/
2016-01-22 22:29:02,330 | INFO | tfatool.sync | File 'stuff/IMG_0800.JPG' already exists; not syncing from SD card
2016-01-22 22:29:02,331 | INFO | tfatool.sync | Copying remote file IMG_0801.JPG to stuff/IMG_0801.JPG
2016-01-22 22:29:02,331 | INFO | tfatool.sync | Requesting file: http://flashair/DCIM/100__TSB/IMG_0801.JPG
2016-01-22 22:29:17,831 | INFO | tfatool.sync | Wrote IMG_0801.JPG in 9.40 s (4.31 MB, 0.46 MB/s)
2016-01-22 22:29:17,833 | INFO | tfatool.sync | File 'stuff/IMG_0802.JPG' already exists; not syncing from SD card
2016-01-22 22:29:17,833 | INFO | tfatool.sync | Copying remote file IMG_0803.JPG to stuff/IMG_0803.JPG
2016-01-22 22:29:17,834 | INFO | tfatool.sync | Requesting file: http://flashair/DCIM/100__TSB/IMG_0803.JPG
2016-01-22 22:29:30,855 | INFO | tfatool.sync | Wrote IMG_0803.JPG in 10.07 s (4.55 MB, 0.45 MB/s)

Other simple --sync-once examples:

  • Just grab the most recent JPEG: flashair-util -S time -n 1
  • Sync most recent 5 files by timestamp: flashair-util -S time --n-files 5
  • Make sure stuff/ local dir and /DCIM remote dir are completely synchronized: flashair-util -S all -y both -d stuff/ -r /DCIM
  • Of all files that end in 08.JPG, sync the 10 greatest filenames: flashair-util -S name --n-files 10 -k '.+08\.JPG'

Example 3: listing files on FlashAir

List all remote files created after 3:00 pm today:

$ flashair-util -l -t 15:00
2016-01-29 16:26:55,287 | INFO | main | Filtering from [2016-01-29 15:00:00] to [end of time]

Files in /DCIM/100__TSB

filename      date        time       MB  created
------------  ----------  ------  -----  -----------
IMG_1184.JPG  2016-01-29  15:03    5.13  7 hours ago
IMG_1184.CR2  2016-01-29  15:03   18.8   7 hours ago
IMG_1185.JPG  2016-01-29  15:03    5.82  7 hours ago
IMG_
View on GitHub
GitHub Stars40
CategoryDevelopment
Updated10mo ago
Forks10

Languages

Python

Security Score

82/100

Audited on May 13, 2025

No findings