sftp_helper.cli_argparse module

SFTP Helper — argparse-based command-line interface.

Thin wrapper around the pure functions in sftp_helper.main that exposes the whole toolkit as subcommands under a single sftp-helper entry point. Written with argparse from the standard library so the CLI works out of the box on any Python install that has the package installed — no extra dependency required.

Every subcommand accepts --config (path to a JSON/YAML file or a directory containing one). When omitted, sftp_helper.credentials falls back to environment variables / .env — same discovery order as the library.

Subcommands

  • upload — upload a local file to the SFTP server

  • download — download a remote file to the local disk

  • delete — delete a remote file

  • exists — check whether a remote file exists (exit code 0/1)

  • dir-exists — check whether a remote directory exists (exit code 0/1)

  • mkdir — create a remote directory (mkdir -p semantics)

  • normalize-path — normalize a remote path (leading ‘/’, no trailing ‘/’)

  • strip-path — strip sftp://<host> prefix from an SFTP address

  • tempfile — reserve a unique remote path (no upload) and print it

  • show-credentials — print the resolved credentials (secret masked)

Usage Example

>>> #   sftp-helper upload         --config sftp_config.json --input local.txt --remote /uploads/local.txt
>>> #   sftp-helper download       --config sftp_config.json --remote /uploads/local.txt --output out.txt
>>> #   sftp-helper delete         --config sftp_config.json --remote /uploads/local.txt
>>> #   sftp-helper exists         --config sftp_config.json --remote /uploads/local.txt
>>> #   sftp-helper dir-exists     --config sftp_config.json --remote /uploads
>>> #   sftp-helper mkdir          --config sftp_config.json --remote /uploads/a/b/c
>>> #   sftp-helper normalize-path --path //foo/bar/
>>> #   sftp-helper strip-path     --config sftp_config.json --address sftp://host/foo/bar
>>> #   sftp-helper tempfile       --config sftp_config.json --ext txt --subdir batch-42
>>> #   sftp-helper show-credentials --config sftp_config.json

Author

Warith Harchaoui, Ph.D. — https://linkedin.com/in/warith-harchaoui/

sftp_helper.cli_argparse.build_parser()[source]

Assemble the top-level sftp-helper argument parser.

Returns:

Fully wired parser with every subcommand attached.

Return type:

argparse.ArgumentParser

sftp_helper.cli_argparse.main(argv=None)[source]

Entry point invoked by sftp-helper (see [project.scripts]).

Parameters:

argv (sequence of str, optional) – Arguments to parse. Defaults to sys.argv[1:] when None.

Returns:

Process exit code (0 on success).

Return type:

int