@vforsh/seafile-cli
v0.1.0
Published
Automation-friendly CLI for discovering and downloading from multiple Seafile instances
Readme
seafile-cli
Automation-friendly CLI for discovering and downloading from multiple Seafile instances.
Scope
Version 1 supports:
- Named Seafile instances with account tokens
- Listing accessible libraries
- Listing directories immediately or recursively
- Finding files and directories by basename glob with depth and time bounds
- Inspecting normalized file and directory metadata
- Listing and downloading historical file revisions
- Downloading files and directories in batches
- Downloading directory ZIPs or extracting them locally
- Human, stable plain-text, and JSON output
- Read-only readiness diagnostics
It does not support indexed content search, encrypted-library access, uploads, or downloading an entire library root.
Install
Requires macOS and Bun 1.2 or newer.
bun add -g @vforsh/seafile-cli
seafile --versionFrom a source checkout:
bun install
bun link
seafile --helpConfigure instances
Add an instance. The command reads the account token from a hidden prompt:
seafile instance add rshub https://cloud.rshub.io
seafile instance add stark https://art.stark.gamesFor non-interactive setup, pipe the token through stdin:
printf '%s' "$TOKEN" | seafile instance add rshub https://cloud.rshub.ioTokens are stored in the XDG config file with mode 0600. They are never accepted as
command-line arguments.
seafile instance list
seafile instance use rshub
seafile cfg pathThe first added instance becomes the default. Override it per invocation:
seafile --instance stark listFor ephemeral automation, skip config entirely:
SEAFILE_URL=https://cloud.rshub.io \
SEAFILE_TOKEN="$TOKEN" \
seafile --json listRemote paths
Remote targets use library:/absolute/path:
Assets:/
Assets:/Characters
Assets:/Characters/hero.pngA unique library name is convenient for humans. A library UUID is canonical and should be used in durable automation:
seafile list 'c0edc6fa-409f-492b-aa18-84cfcd297be8:/content'You can also pass Seafile library browser links (/library/…), file view links
(/lib/…/file/…), or smart links (/smart-link/…) directly to list, find,
stat, and download. Quote the URL. The CLI uses the matching configured instance
or a matching SEAFILE_URL and SEAFILE_TOKEN pair. With --instance, URLs
use the named account's stored URL and token. Smart links need a server that
supports resolving them with an account token.
List
List every accessible library:
seafile list
seafile ls
seafile --json list
seafile --plain listList a directory's immediate children:
seafile list 'Assets:/Characters'
seafile --json list 'Assets:/Characters'List all descendants, optionally filtering by entry type and limiting output:
seafile list 'Assets:/Characters' --recursive
seafile list 'Assets:/' --recursive --type file --limit 100--plain list emits one canonical library-id:/path per entry. At the library level it
emits one library UUID per line.
--require-match exits with an error when a directory listing is empty. Recursive
results are sorted by canonical remote path before --limit is applied.
JSON directory entries use a stable normalized shape: id, name, type,
parentPath, remotePath, permission, mtime, size, modifier, lock, and
starred. Unrecognized server fields are not forwarded.
Use --sort mtime with list <target> or find to sort by newest first before
applying --limit. Missing times sort last. Use --sort path to sort files and
directories together by path. With --json, --fields selects
which fields appear in each entry and keeps the surrounding JSON metadata.
seafile --json list 'Assets:/Characters' --sort mtime --limit 5 --fields remotePath,mtime,sizeFind
Find descendants by a case-sensitive basename glob:
seafile find 'Assets:/' --name '*.png'
seafile find 'Assets:/Characters' --name 'hero*' --type file
seafile --json find 'Assets:/' --name '*.json' --limit 100Quote globs so the local shell does not expand them. Matching is performed against each
entry's basename, not its full path. --limit bounds emitted results after deterministic
sorting; Seafile still enumerates the requested remote tree.
Use --require-match when an empty result should fail automation:
seafile find 'Assets:/' --name 'manifest.json' --require-matchPlain output contains one canonical library-id:/path per match.
Start in the closest known folder. For large trees, use --first to stop after
the first breadth-first match, --max-depth 1 for direct children (increase it
for deeper levels), or --deadline <seconds> for a total search budget including
target resolution, requests, and retries.
seafile --json find 'Assets:/Characters' --name 'hero*' --first --max-depth 2 --deadline 5With these bounds, JSON adds complete and stopReason. If stopped early,
complete is false and total counts matches found so far. A first match is a
success. A deadline exits 1 and still prints partial results when the target
has been resolved. An exhaustive search within --max-depth is complete.
--first uses breadth-first order and cannot be combined with --sort mtime.
Stat
Inspect a file, directory, or library root:
seafile stat 'Assets:/Characters/hero.png'
seafile --json stat 'Assets:/Characters'
seafile --plain stat 'Assets:/'JSON output normalizes the target's type, size, modification time, object ID, current
library revision ID, permission, modifier, and lock state. Fields unavailable on a
server are returned as null, rather than guessed.
History
List a file's historical revisions:
seafile history 'Assets:/Characters/hero.png'
seafile --json history 'Assets:/Characters/hero.png' --limit 100
seafile --plain history 'Assets:/Characters/hero.png' --allThe default limit is 25 revisions. --all explicitly fetches the complete history
available under the library's retention policy and cannot be combined with --limit.
Plain output contains one full commit ID per line.
JSON revisions include the commit ID, file object ID, canonical historical remote path,
previous path for rename events, timestamp, size, description, and author. Use the
revision's own remotePath when downloading history from before a rename:
seafile download \
'c0edc6fa-409f-492b-aa18-84cfcd297be8:/Old/hero.png' \
--revision 0123456789abcdef0123456789abcdef01234567 \
-o ./hero-old.pngDownload
Download a file to its remote basename in the current directory:
seafile download 'Assets:/Characters/hero.png'Choose an exact local output path:
seafile download 'Assets:/Characters/hero.png' -o ./hero.pngDownload an exact historical file revision:
seafile download 'Assets:/Characters/hero.png' \
--revision 0123456789abcdef0123456789abcdef01234567Directories are prepared by Seafile and downloaded as ZIP archives:
seafile download 'Assets:/Characters'
# writes ./Characters.zipSave several targets under their original names with --into. The directory
is created if needed. With --extract, directory targets are unpacked into a
subdirectory named after the remote directory. Extracted directories must have
a fresh destination.
seafile --json download 'Assets:/hero.json' 'Assets:/hero.atlas' 'Assets:/hero.png' --into ./assets
seafile download 'Assets:/Characters' --into ./assets --extractBatch JSON returns { results, failed } with one success or error per input
in input order. Independent targets continue on failure and the command exits 1
if any target failed. Targets that would write the same name report a conflict
before transferring bytes, using the destination filesystem's filename rules.
--output selects an exact path for a single target.
Existing files are left untouched unless --force is passed. Downloads stream to a
temporary sibling file and are published after transfer completes.
seafile download 'Assets:/Characters/hero.png' -o ./hero.png --forceStream downloaded bytes to stdout:
seafile download 'Assets:/manifest.json' -o - | jq .Binary stdout cannot be combined with --json or --plain.
Output contract
- Default: concise human-readable text or tables
--plain: stable line-oriented IDs or paths--json: one JSON object on stdout- Primary data: stdout
- Progress, diagnostics, and human errors: stderr
- JSON-mode errors:
{ "error": { "code", "message", "exitCode" } }on stdout --quiet: suppress progress and diagnostics--verbose: show sanitized request diagnostics
Exit codes:
0: success1: runtime, config, authentication, network, or remote-operation failure2: invalid command usage130: interrupted secure input
Config
Default path:
${XDG_CONFIG_HOME:-~/.config}/seafile/config.jsonSEAFILE_CONFIG overrides the full path.
seafile cfg list
seafile cfg get defaultInstance timeoutMs retries
seafile cfg set timeoutMs=45000 retries=3
seafile cfg unset defaultInstanceSecret keys must come from stdin:
printf '%s' "$TOKEN" | seafile cfg set instances.rshub.token -Config can be round-tripped for agent setup:
seafile cfg export --json > seafile-config.json
seafile cfg import --json < seafile-config.jsoncfg export --json includes account tokens. Treat its output as a secret.
Precedence, highest first:
- CLI flags
SEAFILE_*environment variables- XDG config
Supported environment variables:
SEAFILE_INSTANCESEAFILE_URLSEAFILE_TOKENSEAFILE_CONFIGSEAFILE_TIMEOUT_MSSEAFILE_RETRIESXDG_CONFIG_HOMENO_COLOR
Diagnostics
doctor is read-only. It checks Bun, config parsing and access, selected credentials,
authentication, reachability, and server version.
seafile doctor
seafile check --jsonAgent skill
Print the installable skill URL:
seafile skillInstall it with:
npx skills add "$(seafile skill)"Development
bun install
bun run typecheck
bun test
bun linkLicense
MIT
