To help prevent overwhelming network devices while pasting in large configuration files, user miked on the Van Dyke forums provided a script that you can use in SecureCRT.
Save the appropriate script somewhere you can browse for it in later steps.
The script can also be downloaded from the aforementioned post; once downloaded, remove the .txt file extension so SecureCRT recognizes it.
- PasteWithEchoFlowControl.vbs.txt - VBS script for Windows users.
- PasteWithEchoFlowControl.py.txt - Python script for Linux users.
# $language = "VBScript" # $interface = "1.0" ' PasteWithFlowControl.vbs ' Last Modified: 21 Mar, 2012 ' ' DESCRIPTION: ' Demonstrates how to send data from the Windows Clipboard to a remote system, ' sending each line one at a time and waiting for prior lines to be echoed ' back by the remote system before moving on with sending subsequent lines. ' This is one approach to prevent overwhelming remote hosts like cisco ' devices that don't implement any SSH flow control and therefore are ' incapable of accepting data as fast as SecureCRT normally sends it. crt.Screen.Synchronous = True crt.Screen.IgnoreEscape = True Sub Main() ' If there isn't an active connection, there's no point in continuing ' since we can't send data. If Not crt.Session.Connected Then crt.Dialog.MessageBox "Sending data requires an active connection." Exit Sub End If ' If there isn't anything in the Windows Clipboard, it doesn't make any ' sense to continue with the script. If Trim(crt.Clipboard.Text) = "" Then crt.Dialog.MessageBox "No text found in the Windows Clipboard." Exit Sub End If ' Keep timing information so that we can display how long it took for the ' data to be sent to the remote (each line sent only after the prior line ' was echoed back to SecureCRT, as a flow control mechanism). nStartTime = Timer ' Multiple lines in the Windows Clipboard are typically stored with a CRLF ' separator, but this script example tries to accommodate other line endings ' that might be supported by some editors. Break up lines into an array ' (each line as an element within the array). If Instr(crt.Clipboard.Text, vbcrlf) > 0 Then vLines = Split(crt.Clipboard.Text, vbcrlf) ElseIf Instr(crt.Clipboard.Text, vblf) > 0 Then vLines = Split(crt.Clipboard.Text, vblf) Else vLines = Split(crt.Clipboard.Text, vbcr) End If nLineNumber = 0 For Each strLine In vLines ' Send the next line to the remote crt.Screen.Send strLine & vbcr ' Wait for the remote to echo the line back to SecureCRT; bail if the ' remote fails to echo the line back to us within 3 seconds. If Not crt.Screen.WaitForString(strLine, 3) Then crt.Dialog.MessageBox _ "Sent " & nLineNumber + 1 & " lines, but the last one was " & _ "not echoed back to SecureCRT within 3 seconds." & vbcrlf & _ vbcrlf & _ "Abandoning paste operation." Exit Sub End If nLineNumber = nLineNumber + 1 Next ' Inform that the data has all been sent. crt.Dialog.MessageBox _ nLineNumber & " lines from the clipboard have been sent." & _ vbcrlf & vbcrlf & _ "Time elapsed: " & GetMinutesAndSeconds(Timer - nStartTime) End Sub '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Function GetMinutesAndSeconds(nTotalSecondsElapsed) Dim nMinutes, nSeconds, nMSeconds Dim nMinutesElapsed, nSecondsValue, nSecondsElapsed If nTotalSecondsElapsed = 0 Then GetMinutesAndSeconds = "less than a millisecond." Exit Function End If ' convert seconds into a fractional minutes value nMinutesElapsed = nTotalSecondsElapsed / 60 ' convert the decimal portion into the number of remaining seconds nSecondsValue = nMinutesElapsed - Fix(nMinutesElapsed) nSecondsElapsed = Fix(nSecondsValue * 60) ' Remove the decimal from the minutes value nMinutesElapsed = Fix(nMinutesElapsed) ' Get the number of Milliseconds, Seconds, and Minutes to return to the ' caller byref nMSeconds = fix(1000 * (nTotalSecondsElapsed - Fix(nTotalSecondsElapsed))) nSeconds = nSecondsElapsed nMinutes = nMinutesElapsed ' Form the final string to be returned GetMinutesAndSeconds = nMinutesElapsed & " minutes, " & _ nSecondsElapsed & " seconds, and " & _ nMSeconds & " ms" End Function
# $language = "python" # $interface = "1.0" # PasteWithEchoFlowControl.py # # Description: # Demonstrates how to send a block of lines from the clipboard and # wait for those lines to be echoed back by the remote host before the next # block of lines is sent. This is one approach to prevent overwhelming a # remote host that cannot accept data as fast as SecureCRT normally sends it # by making sure the remote machine has received each block of lines before # moving on with the next block. import SecureCRT import time crt.Screen.Synchronous = True crt.Screen.IgnoreEscape = True def main(): # If there isn't an active connection, there's no point in continuing # since we can't send data. if not crt.Session.Connected: crt.Dialog.MessageBox("Sending data requires an active connection.") return # If there isn't anything in the clipboard, it doesn't make any # sense to continue with the script. if crt.Clipboard.Text.strip() == "": crt.Dialog.MessageBox("No text found in the clipboard.") return # Keep timing information so that we can display how long it took for the # data to be sent to the remote (each line sent only after the prior line # was echo'd back to SecureCRT, as a flow control mechanism). nStartTime = time.time() # Multiple lines in the clipboard are typically stored with a CRLF # separator, but this script example tries to accommodate other line endings # that might be supported by some editors. Break up lines into an array # (each line as an element within the array). if crt.Clipboard.Text.find("\r\n") > -1: vLines = crt.Clipboard.Text.split("\r\n") elif crt.Clipboard.Text.find("\n") > -1: vLines = crt.Clipboard.Text.split("\n") else: vLines = crt.Clipboard.Text.split("\r") nLineNumber = 0 for strLine in vLines: # Send the next line to the remote crt.Screen.Send(strLine + "\r") bSuccess = False # If the current line isn't empty, wait for it to be echo'd back to us if not strLine == "": # Wait for the remote to echo the line back to SecureCRT; bail if # the remote fails to echo the line back to us within 3 seconds. bSuccess = crt.Screen.WaitForString(strLine, 3) else: crt.Session.SetStatusText( "Sent a blank line; waiting for cursor to move...") bSuccess = crt.Screen.WaitForCursor(3) crt.Session.SetStatusText("") if not bSuccess: crt.Dialog.MessageBox( "Sent %d lines, but the most recent line sent " % (nLineNumber + 1) + "was not echoed back to SecureCRT within 3 seconds.\r\n\r\n" + "Abandoning paste operation.") return nLineNumber += 1 # Calculate seconds elapsed nTimeElapsed = time.time() - nStartTime # Inform that the data has all been sent. crt.Dialog.MessageBox( "%d lines from the clipboard have been sent.\r\n\r\n" % (nLineNumber) + "Time elapsed: %2.3f seconds." % (nTimeElapsed)) main()
Perform the following steps to add the button...
|How to create the button in SecureCRT|
|In SecureCRT menus, select View > Button Bar.|
|Right click on the button bar (bottom of window) and select New Button.|
|A Map Button window will appear; in the Function menu, choose Run Script.|
|Enter a label to describe the button (ie. Echo Flow Control Paste), click the
|Click OK, and the new button will be in the button bar.|
Now when the button is hit the script will run and paste the clipboard contents, waiting for each line to be echo’ed before sending the next line.