Sample code for 30+ languages & platforms
Classic ASP

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 Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
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 = Server.CreateObject("Chilkat.SFtp")

'  Step 1: Connect the SSH transport.  Port 22 is the usual port.
port = 22
success = sftp.Connect("sftp.example.com",port)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( sftp.LastErrorText) & "</pre>"
    Response.End
End If

'  Begin keyboard-interactive authentication.  The returned XML describes the server's prompts.
infoRequestXml = sftp.StartKeyboardAuth("mySshLogin")
If (sftp.LastMethodSuccess = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( sftp.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( infoRequestXml) & "</pre>"

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

sftp.Disconnect 

%>
</body>
</html>