PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkSFtp.pb"
Procedure ChilkatExample()
success.i = 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.
sftp.i = CkSFtp::ckCreate()
If sftp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Step 1: Connect the SSH transport. Port 22 is the usual port.
port.i = 22
success = CkSFtp::ckConnect(sftp,"sftp.example.com",port)
If success = 0
Debug CkSFtp::ckLastErrorText(sftp)
CkSFtp::ckDispose(sftp)
ProcedureReturn
EndIf
; Begin keyboard-interactive authentication. The returned XML describes the server's prompts.
infoRequestXml.s = CkSFtp::ckStartKeyboardAuth(sftp,"mySshLogin")
If CkSFtp::ckLastMethodSuccess(sftp) = 0
Debug CkSFtp::ckLastErrorText(sftp)
CkSFtp::ckDispose(sftp)
ProcedureReturn
EndIf
Debug infoRequestXml
; Answer the prompt(s) with ContinueKeyboardAuth, then call InitializeSftp.
CkSFtp::ckDisconnect(sftp)
CkSFtp::ckDispose(sftp)
ProcedureReturn
EndProcedure