Skip to content

PromptingCommand

Nicolas Couture edited this page Apr 19, 2026 · 1 revision

PromptingCommand

PromptingCommand is a specialized subclass of SSHCommand designed for multi-step interactions, such as password prompts or confirmation dialogs.

Usage

It uses a sequence of callbacks to transition through different states of an interaction.

import MockSSH

def on_success(instance):
    instance.writeln("Access Granted.")
    instance.protocol.prompt = "admin# "

def on_failure(instance):
    instance.writeln("Access Denied.")

# Define the command
secret_gate = MockSSH.PromptingCommand(
    name="enable",
    password="supersecret",
    prompt="Password: ",
    success_callbacks=[on_success],
    failure_callbacks=[on_failure]
)

How it Works

  1. When the user types enable, the server displays the prompt ("Password: ").
  2. The server enters a "password mode" where input is not echoed back.
  3. Once the user presses Enter, the input is compared against the password.
  4. If it matches, all success_callbacks are executed; otherwise, failure_callbacks run.
  5. The command then automatically exits.

Clone this wiki locally