VanDyke Software Forums

VanDyke Software Forums (
-   Scripting (
-   -   Re-attempt SSH login. (

arortizg 03-20-2021 11:46 AM

Re-attempt SSH login.
Hello Forum.

Hope all of you are doing fine.

I'm having this problem which I'm sure you have already encountered and fix, but I haven't been able to find an answer yet in the forum.

I'm using this script to logging into multiple devices through SSH2. The problems relies when the first Username and Password fail, then I attempt to use a second Username and Password but the programs seems to never reach that part of the code because a Error window pops saying "Keyboard-Interactive authentication with the SSH2 server failed" and wont let the "else" to execute, any idea on how to make the program try another set of username and password if the the first one failed?


# $language = "python"
# $interface = "1.0"

# This script demonstrates how to open a text file and read it line by
# line to a server.


devices = ["",

def mainConnection():

    for dev in devices:

            crt.Session.ConnectInTab("/SSH2 /L USERNAME1 /PASSWORD PASSWORD1 " + dev)
        except ScriptError:
            error = crt.GetLastErrorMessage()

        if crt.Session.Connected == True:
            crt.Dialog.MessageBox("Connection successful " )
            ###This is the line of code that wont execute if the first username and pass fail.
            crt.Session.ConnectInTab("/SSH2 /L USERNAME2 /PASSWORD PASSWORD2 " + dev)

def main():



bgagnon 03-21-2021 01:06 PM

Hi arortizg,

The ConnectInTab() method takes an optional parameter which determines whether the call fails silently or raises an exception:


Takes the same arguments as Connect. This also returns a Tab object.

The ConnectInTab method also takes two optional parameters (True or False). The first determines whether or not the script should wait for the connection to fully authenticate before continuing. The first parameter only applies to SSH1 and SSH2 connections. The second optional parameter specifies whether the call fails silently or raises an exception. If the second parameter is False and the connection attempt fails, an exception is raised and the method returns an empty object. If the second parameter is True and the connection attempt fails, the method returns a valid Tab object, which can then be used to check for connection status in order to determine if the connection attempt was successful.
And then a relevant line of info from Connect() method:

The Connect method also takes an optional parameter (True or False) that specifies whether or not to suppress pop-up messages. This parameter defaults to False (don't suppress).

bgagnon 03-31-2021 09:49 AM

Hi arortizg,

Also, you will likely need to enable the Display logon prompts in terminal window option in the Connection / Logon Actions category of Session Options. You would make that change to Default session since you are making ad hoc connections in your script.

All times are GMT -6. The time now is 01:42 PM.