Sample code for 30+ languages & platforms
PowerBuilder

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Sftp
integer li_Port
string ls_InfoRequestXml

li_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.

loo_Sftp = create oleobject
li_rc = loo_Sftp.ConnectToNewObject("Chilkat.SFtp")
if li_rc < 0 then
    destroy loo_Sftp
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Step 1: Connect the SSH transport.  Port 22 is the usual port.
li_Port = 22
li_Success = loo_Sftp.Connect("sftp.example.com",li_Port)
if li_Success = 0 then
    Write-Debug loo_Sftp.LastErrorText
    destroy loo_Sftp
    return
end if

//  Begin keyboard-interactive authentication.  The returned XML describes the server's prompts.
ls_InfoRequestXml = loo_Sftp.StartKeyboardAuth("mySshLogin")
if loo_Sftp.LastMethodSuccess = 0 then
    Write-Debug loo_Sftp.LastErrorText
    destroy loo_Sftp
    return
end if

Write-Debug ls_InfoRequestXml

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

loo_Sftp.Disconnect()


destroy loo_Sftp