#$language = "Python" #$interface = "1.0" # SFTP_Tab_ConnectionLogonScript(close-shell-tab).py # # Description: # ----------------------------------------------------------- # This example is designed to be used as a logon script for # a copy of an existing SSH2 session. Suggestion is to name # the copy with "-SFTP", and configure it with a Logon script # in the Session Options / Logon Actions category set to this # script file. The script will a) connect, b) create an SFTP # tab using the established SSH2 connection, and then c) # close the original SSH2 shell tab. If the SSH2 server does # not support SFTP connections, this script will fail. objCurTab = crt.GetScriptTab() # First, let's fix this session copy so that a shell channel # isn't requested in the future: strOptionName = "Request Shell" nOptionValue = objCurTab.Session.Config.GetOption(strOptionName) if nOptionValue: objCurTab.Session.Config.SetOption(strOptionName, False) objCurTab.Session.Config.Save() # Now, connect an SFTP channel using the established # connection objSFTPTab = objCurTab.ConnectSftp() objSFTPTab.Screen.Synchronous = False # Wait for the "sftp>" prompt to appear... while not objSFTPTab.Screen.Get( objSFTPTab.Screen.CurrentRow, 1, objSFTPTab.Screen.CurrentRow, len("sftp>")) == "sftp>": crt.Sleep(125) # Now, close the original tab (this script will # exit as a result) objCurTab.Activate() # Avoid the "Confirm Disconnect" dialog, if possible: [nMajor, nMinor, nMaint] = ((crt.Version).split())[0].split(".") if (int(nMajor) >= 9) or ([nMajor, nMinor].join('.') == "8.7"): crt.Config.SetOption("Show Confirm Disconnect Dialog", False) # Now, close the screen objCurTab.Screen.SendSpecial("MENU_TAB_CLOSE")