ASCII File Send

Here is a script implementation of a feature I get asked for a lot:  ASCII file send.  If you just want to take the contents of a file and send it to the remote host, this script is for you!  This is not a file transfer.  No SFTP or ZModem here. This is more like opening the file in a notepad, copying it to the clipboard, then pasting it into the terminal session.  The example opens a file “c:\sample.txt”, then reads the contents and sends the entire thing to the host using AbsoluteTelnet’s Terminal.SendText function.

Sub Main
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\\sample.txt")
If objFile.Size > 0 Then
Set objReadFile = objFSO.OpenTextFile("C:\\sample.txt", 1)
strContents = objReadFile.ReadAll
Terminal.SendText strContents
objReadFile.Close
Else
MsgBox "The file is empty."
End If
End Sub

It makes most sense to implement this as a user initiated script via the keyboard mapping function.  To do this, go to the Options->Properties->VTOptions page and do the following:

  1. Click the “edit keymap” button.
  2. On the key mapping dialog, click “add”.
  3. You’ll be prompted for a key combination to remap.  Click any key or key combination that you want to use to perform the script (F7 for example).  F7 will now be remapped.
  4. Now, you’re prompted for the text to map F7 to.  In previous versions of Absolute, you could only enter a text string here to send to the host when F7 is pressed.  In Absolute 7, you can enter your script, but be sure to enter the first line as the text “VBSCRIPT”  This tells Absolute that the remainder of the text is a script to execute… (see below)
  5. Click Ok
  6. Click Ok
  7. Click OK

Back at the terminal screen, press F7 to send the file.  If the file cannot be found or it is empty, you should get error messages on the screen to help you determine the problem.  You can modify this script to change the location of the file or even to prompt the user for the name of the file!  This is a simple example to demonstrate the capabilites of AbsoluteTelnet scripting.  The rest is up to you!

VBSCRIPT
Sub Main
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\\sample.txt")
If objFile.Size > 0 Then
Set objReadFile = objFSO.OpenTextFile("C:\\sample.txt", 1)
strContents = objReadFile.ReadAll
Terminal.SendText strContents
objReadFile.Close
Else
MsgBox "The file is empty."
End If
End Sub

Leave a Comment

Your email address will not be published. Required fields are marked *