Sample code for 30+ languages & platforms
Tcl

Start SFTP Keyboard-Interactive Authentication

See more SFTP Examples

Demonstrates the Chilkat SFtp.StartKeyboardAuth method, which begins keyboard-interactive authentication. The only argument is the login name. It returns XML describing the server's prompts, which are answered with ContinueKeyboardAuth.

Background: Keyboard-interactive is the prompt-driven authentication method: rather than assuming a single password, the server sends one or more questions — a password, a one-time code, a security question — and the client answers each. This is how SFTP supports two-factor and other challenge-response schemes. The returned XML tells you exactly what to ask and whether to mask the input.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

#  Demonstrates the SFtp.StartKeyboardAuth method, which begins keyboard-interactive
#  authentication.  The only argument is the login name.  It returns XML describing the server's
#  prompts, which are answered with ContinueKeyboardAuth.

set sftp [new_CkSFtp]

#  Step 1: Connect the SSH transport.  Port 22 is the usual port.
set port 22
set success [CkSFtp_Connect $sftp "sftp.example.com" $port]
if {$success == 0} then {
    puts [CkSFtp_lastErrorText $sftp]
    delete_CkSFtp $sftp
    exit
}

#  Begin keyboard-interactive authentication.  The returned XML describes the server's prompts.
set infoRequestXml [CkSFtp_startKeyboardAuth $sftp "mySshLogin"]
if {[CkSFtp_get_LastMethodSuccess $sftp] == 0} then {
    puts [CkSFtp_lastErrorText $sftp]
    delete_CkSFtp $sftp
    exit
}

puts "$infoRequestXml"

#  Answer the prompt(s) with ContinueKeyboardAuth, then call InitializeSftp.

CkSFtp_Disconnect $sftp

delete_CkSFtp $sftp