Skip to content
Syno Package Land
Language: English

Run ctl commands

How to call the commands an App exposes, from a terminal, a script or an AI agent. To make an App expose commands, see Expose App commands; what is checked and refused is in ctl security.

CommandDoes
host add <name> --url <https-origin>Register a NAS and sign in.
host list / host show <name>List hosts and session state / show approvals and hash pins.
host login <name>Renew an expired sign-in.
host logout <name>Sign out of DSM; keep the registration.
host remove <name> --yesDelete the registration and everything stored for it.
host revoke <name> <PackageID>Withdraw one App’s approval and clear the host’s description cache.
ctl listDiscover Apps and their commands.
ctl <alias or package> <command...>Run a command.
ctl <alias or package> [command...] --help, ctl help <alias or package> [command...]Show one App or command with its schema and examples.
Terminal window
synopkgland host add nas --url https://nas.example:5001 --username alice
printf '%s' "$DSM_PASSWORD" | synopkgland host add nas --url https://nas.example:5001 --username alice --password-stdin
OptionMeaning
--urlRequired on add. An https:// origin with no path, query or credentials.
--usernameThe DSM account. Prompted if omitted.
--password-stdinRead the password from stdin (up to 4096 bytes).
--ssh-tunnelAllow http://127.0.0.1 or http://[::1] for an SSH tunnel to the NAS.
--no-remember-deviceDo not keep a DSM device token; OTP is asked at every sign-in.
  • Password and OTP prompts are hidden. Never pass them as arguments.
  • An account with OTP needs a terminal for the six-digit code, unless a remembered device token exists. Without a terminal and without --password-stdin the command fails with CTL_INTERACTION_REQUIRED.
  • Host names are letters, digits, ., _ and -, up to 64 characters. A name that exists gives CTL_HOST_EXISTS; use host login to renew it. To change the URL or account, add a second host name.
  • There is no current host. One registered host is used by default. With several, give --host nas, --host a,b or --all-hosts, otherwise CTL_HOST_REQUIRED (exit 3). Up to 4 hosts run in parallel.

Certificate trust, --strict-tls, --ca, host trust, environment credentials and session storage are shared by every command; see CLI reference.

Terminal window
synopkgland ctl list --host nas --json
synopkgland ctl list --host nas --app MyApp --json
synopkgland ctl list --host nas --refresh --json
  1. ctl lists the installed packages with your session.
  2. Before it reads any description it shows the candidate package@version batch and asks once. Without a terminal, pass --approve-installed. An agent must get the user’s authorization first.
  3. It reads each App’s description, validates it and pins its hash. Same version and hash: the cache is used. --refresh reads again.
  4. A new version needs approval again. A changed hash for the same version gives CTL_DESCRIPTION_CHANGED; approve with --refresh --approve-installed only after you know why.

--app <package> narrows the batch to one package. The result:

FieldContent
apps[]One entry per valid App: package, aliases, protocolVersion, developedBy (provenance is always self-declared), hash, commands[].
commands[]id, summary, cli, effect, permission, parameters (the schema, or a note that parameters are undescribed), flow, examples (runnable command lines).
diagnostics[]Apps left out, each with package, code, message, hint. Codes: CTL_TRUST_REQUIRED, CTL_DESCRIPTION_CHANGED, CTL_DESCRIPTION_UNAVAILABLE, CTL_DESCRIPTOR_INVALID.
cacheHitsHow many descriptions came from the cache.

Only valid Apps appear as commands. A failed App is a diagnostic and never runs. Discovery that returns diagnostics still exits 0.

Terminal window
synopkgland ctl myapp status --host nas
synopkgland ctl myapp notes add --text "Buy milk" --host nas --dry-run
synopkgland ctl myapp notes add --text "Buy milk" --host nas --yes
synopkgland ctl myapp notes add --host nas --help
  • The alias and the package ID are case-insensitive. The command words end at the first -- token.
  • A mistyped App, command or host returns the closest match in the message and the full list in error.allowed.
  • Reads run directly. A write or destructive command without --yes runs nothing, returns the plan and exits 7. Run it again with --yes.
  • --dry-run returns the request ctl would send and sends no business request. It still needs a stored sign-in and reads the App descriptions.
  • --yes is not authorization. The App still checks the DSM user, App Privileges, owner, ACL and grants.
{"ok":true,"data":{"dryRun":true,"request":{"package":"MyApp","version":"0.1.0-0001","path":"/webman/3rdparty/MyApp/cgi/api.cgi","command":"notes.add","flow":{"type":"invoke","method":"notes.add"},"params":{"text":"Buy milk"},"effect":"write"}}}
  • string, integer, number and boolean parameters are typed flags: --text "Buy milk", --text=Hello, --limit 20. A boolean flag alone means true; --flag false sets it off. Integers must be safe integers.
  • Defaults of top-level properties are filled in; a default inside a nested object is not, so send nested values in --input. Required, type, enum and range errors are rejected before any request (CTL_PARAMS_INVALID, exit 3). The error never repeats your values.
  • Arrays and objects, and commands without a schema, take --input file.json or --input - (stdin). --input must be the only argument; the input is one strict JSON object of at most 1 MiB.
  • Flag values are in the process arguments, visible to other local users and shell history. Send secrets through --input -.

Reserved flag names, which a parameter cannot use as a typed flag (it must use --input): --ca, --strict-tls, --host, --all-hosts, --json, --app, --refresh, --yes, --dry-run, --approve-installed, --help, --input, --wait, --no-wait, --timeout.

  • Without a terminal on stdout the output is compact JSON. --json forces it. In a terminal it is indented JSON.
  • One host: {"ok":true,"data":...} or {"ok":false,"error":{"code","message","hint","allowed?","plan?"}}. Follow hint; allowed is the complete list of valid values.
  • Several hosts: {"ok":false,"results":[{"host":"nas","ok":true,"data":...},{"host":"lab","ok":false,"error":...}]}. Each host has its own envelope.
  • Sensitive values print as <redacted> in plans, dry runs, errors and output; the real request is unchanged.
ExitMeaningCodes
0Completed, including help and --dry-run.
1Unexpected internal error, or an uncaught CLI exception.CTL_INTERNAL
2Sign-in or session failure, or no usable credential store.CTL_NOT_AUTHENTICATED, CTL_AUTH_FAILED, CTL_CREDENTIAL_MISMATCH, CTL_CREDENTIAL_STORE, CTL_INTERACTION_REQUIRED, CTL_OTP_INVALID
3Invalid parameters, flags or names.CTL_PARAMS_INVALID, CTL_ARGUMENT_INVALID, CTL_APP_UNKNOWN, CTL_COMMAND_UNKNOWN, CTL_HOST_UNKNOWN, CTL_HOST_REQUIRED, CTL_APP_AMBIGUOUS
4Permission refused.CTL_PERMISSION_DENIED, CTL_INVENTORY_DENIED, CTL_METHOD_NOT_ALLOWED, CTL_ORIGIN_MISMATCH
5App or contract failure.CTL_APP_ERROR, CTL_RESPONSE_INVALID, CTL_JOB_FAILED, CTL_APP_SESSION, CTL_FLOW_LIMIT, CTL_FLOW_RESPONSE, CTL_FLOW_UNSUPPORTED, CTL_TRANSFER_FAILED, CTL_RESPONSE_TOO_LARGE, CTL_INVENTORY_INVALID
6Network or HTTP failure, or uncertain completion.CTL_NETWORK, CTL_HTTP_ERROR, CTL_JOB_TIMEOUT, CTL_LOGOUT_FAILED
7Confirmation required. Nothing ran.CTL_CONFIRM_REQUIRED
8A multi-host command had at least one failed host, including when all failed.
  • Any other ctl error without its own code exits 3 (for example CTL_HOST_EXISTS, CTL_URL_INVALID, CTL_INPUT_FILE).
  • The diagnostic codes of ctl list are not exit codes. Running an App that discovery left out gives CTL_APP_UNKNOWN (exit 3), and no business request is sent.
  • host list and host show exit 0 even with authenticated: false. Read the field.
  • With several hosts, exit 8 hides the per-host codes. Read each results[].error.code.
  • A missing session fails with 2 before confirmation is checked; 7 appears once discovery and validation succeeded.
  • check, build, inspect, status and test propagate their own exit code as well.
Terminal window
out=$(synopkgland ctl myapp status --host nas --json); status=$?
case $status in
0) printf '%s' "$out" | jq -r '.data.user' ;;
2) echo "sign in again: host login nas" >&2 ;;
7) echo "write needs --yes" >&2 ;;
*) printf '%s' "$out" | jq -r '.error.hint' >&2 ;;
esac
FlowWhat you getNotes
invokeThe method’s data.One request.
jobThe job result once done.Waits by default. --no-wait returns {"accepted":true,"job":...} at once. --timeout <seconds> (1 to 3600) overrides the declared limit. A failed state is CTL_JOB_FAILED (5); a timeout is CTL_JOB_TIMEOUT (6), and the job may still be running.
paginate{"items":[...]} from all pages.Reads only. Over 100000 items or the page limit is an error, never a silent partial list.
ndjson{"items":[...]} from the line stream.At most 8 MiB and 10000 lines.
uploadThe App’s response.Typed flags carry the local file, the target parent and name, as the command’s schema names them. One regular file, up to 16 GiB, streamed once.
  • ctl never replays a request. After a network error or timeout the outcome is unknown: read the App’s state before repeating a write.
  • A job start is never repeated. After CTL_JOB_TIMEOUT query the job through the App.
  • Exit 7 means nothing ran; repeat with --yes if authorized.
  • After exit 8, do not rerun the whole command. Check the hosts that failed, then target them with --host.
  • --timeout <seconds> accepts 1–3600 and applies to discovery, JSON requests, polling and transfer inactivity. The default transport allowance is 62 seconds; calls within one operation share its remaining allowance.
  1. host list --json. Check authenticated. If not, ask the user to run host login.
  2. ctl list --host H --json. On CTL_TRUST_REQUIRED diagnostics ask the user to approve the batch. Do not approve it yourself.
  3. Pick a command from commands[]. Use its examples as the syntax.
  4. Run with --dry-run, and with --yes only for an operation the user authorized.
  5. Branch on ok, error.code and the exit code. Follow error.hint. Do not bypass ctl with raw HTTP or guessed methods.
  6. Always name the host with --host.
ItemWhere
Registrations, approvals, pins~/.synopkgland/ctl/hosts/<name>.json, mode 0600. SYNOPKGLAND_CTL_DIR changes the directory.
Description cache~/.synopkgland/ctl/cache/, mode 0600.
Session cookie, SynoToken, device tokenThe OS credential store, service synopkgland.ctl. Never the password or OTP.