Session Object

From SecureCRT

A data path or circuit between two computers over a phone line, network cable, or other means.

A session is a set of options that are assigned to a connection to a remote machine. These settings and options are saved under a session name and allow the user to have different preferences for different hosts.

Telnet is a protocol that provides an interface for communications between clients and servers.

Telnet is a protocol that provides an interface for communications between clients and servers.

To close a Telnet or other type of communication connection between a client and a server.


 

Description

The Session object provides access to the state and properties that exist for the current connection or session.

 

Syntax

session.Property [ = expression ]

session.Method([arglist])

 

Remarks

SecureCRT's Session object is accessed through the top-level object’s Session property.

 

Session Object Properties and Methods

Properties

Methods

    Config

    Connect

    Connected

    ConnectInTab

    LocalAddress

    Disconnect

    LogFileName

    Log

    Logging

    LogUsingSessionOptions

    Path

    Print

    RemoteAddress

 

    RemotePort

 

 

Properties

 

Config

Description

Returns the configuration associated with the session.

Syntax

Set objectvarname = object.Config

Remarks

This configuration will not be saveable to a new name.

 

Example:

Set config = crt.Session.Config

 

Connected

Description

Returns a Boolean value indicating whether the current session is connected or not.

Syntax

[ varname = ] object.Connected

Remarks

Boolean read-only property.

 

LocalAddress

Description

Returns the IP address of the local machine in the form of a string.

Syntax

[ varname = ] object.LocalAddress

Remarks

LocalAddress is a read-only string property. The LocalAddress property should only be accessed if the session is connected. Attempting to access LocalAddress while not connected is an error.

 

LogFileName

Description

Returns or sets the name of the current log file.

Syntax

[ varname = ] object.LogFileName [ = filename ]

Remarks

If filename is invalid a runtime error is generated. See also: session.Log

 

Logging

Description

Returns a Boolean value indicating whether the current session is logging or not.

Syntax

[ varname = ] object.Logging

Remarks

Boolean read-only property.

 

Path

Description

Returns the path for the current session starting from location of the session INI files.

Syntax

[ varname = ] object.Path

Remarks

Path is a read-only string property that returns the path for the current session starting from location of the session INI files. For example, under Windows XP/2000, the default location is:

 

C:\Documents and Settings\<user>\Application Data\VanDyke\SecureCRT\Config\Sessions

 

Under Windows Me/NT, the default location is:

 

C:\Program Files\SecureCRT\Config\Sessions

 

 If no session has been selected, this function will return the name "Default".

 

Example:

If crt.session.path = "work\server0" Then

    myprompt = "linux"

End If

 

RemoteAddress

Description

Returns the IP address of the remote host in the form of a string.

Syntax

[ varname = ] object.RemoteAddress

Remarks

RemoteAddress is a read-only string property. The RemoteAddress property should only be accessed if the session is connected. Attempting to access RemoteAddress while not connected is an error.

 

RemotePort

Description

Returns the port number of the remote port.

Syntax

[ varname = ] object.RemotePort

 

Methods

Connect

Description

Connects to a session.

Syntax

object.Connect [arg [, True|False]]

Remarks

The Connect method takes a string parameter that specifies how a connection is to be made. The format of the string parameter matches the format of the command line arguments to SecureCRT.

The Connect method can accept an empty argument set. The command crt.Session.Connect() means "connect to the current session". If a connection has not been made before, the command will fail. If a connection already exists, nothing happens, otherwise, this command is equivalent to pressing the Reconnect button.

 

Examples:

Connect using a predefined session:

crt.session.Connect("/s mysession")

 

Connect to "myhost" on port 2345 using the Telnet protocol and Default session parameters:

crt.session.Connect("/telnet myhost 2345")

 

The Connect method also takes a final parameter (True or False) that determines whether or not the script should wait for the connection to fully authenticate before continuing. For instance, the connect call in the example below will wait until the connection has been fully authenticated before returning and allowing the script to execute the error check just below the connect call. This parameter only applies to SSH1 and SSH2 connections.

 

Example:

# $language = "VBScript"

# $interface = "1.0"

On Error Resume Next

crt.Session.Connect "/SSH2 /PASSWORD password username@hostname", True

If Err.Number <> 0 Then

    MsgBox "Connection Failed"

Else

    MsgBox "Connection Successful"

End If

 

Whereas, passing False in this case would allow the error check to execute before the connection has a chance to finish. You will probably want to use False only in cases where you want to script the logon process for the session you are attempting to connect to. The default value for this parameter is True.

 

ConnectInTab

Description

Connects to a session in a tab.

Syntax

Set objTab = object.ConnectInTab [arg [, True|False]]

Remarks

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

 

Examples:

Connect in a tab using a predefined session:

Set tab = crt.session.ConnectInTab("/s mysession")

 

Connect in a tab to "myhost" on port 2345 using the Telnet protocol and Default session parameters:

Set tab = crt.session.ConnectInTab("/telnet myhost 2345")

 

The ConnectInTab method also takes a final parameter (True or False) that determines whether or not the script should wait for the connection to fully authenticate before continuing. For more information and an example, see the Connect method above. This parameter only applies to SSH1 and SSH2 connections.

 

Disconnect

Description

Disconnects the current session.

Syntax

object.Disconnect

Remarks

If the current session is not connected, Disconnect does nothing.

 

Log

Description

Enables or disables logging.

Syntax

object.Log(start[, append[, raw]])

Remarks

Starts or stops logging depending on the Boolean state of the "start" parameter. When logging is being started the optional Boolean "append" and "raw" parameters may be set to True to open the log file for appending or to log raw characters respectively. The append and raw parameters are optional and are false if not specified (When "start" is false the values of append and raw are ignored).

 

LogUsingSessionOptions

Description

Turns on logging using the logging options for the current session.

Syntax

object.LogUsingSessionOptions

Remarks

If the session is an ad hoc session, the Default session's logging options will be used.

 

Print

Description

Starts or stops autoprint.

Syntax

object.Print(start)

Remarks

Starts or stops autoprint depending on the Boolean start parameter.