VKontakte.DJ
forum traveling
Home Support Scripting Home Script Examples VBScript example: ascii file send

VBScript example: ascii file send

E-mail Print

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

 

 

Related Links: VBScript API , Scripting Home

Last Updated on Friday, February 27, 2009 01:23 am  

Recent Forum Posts

info in AbsoluteTelnet General by bpence, Apr 24, 2017 12:50 pm
info in AbsoluteTelnet General by bpence, Apr 24, 2017 12:48 pm
info in AbsoluteTelnet General by bpence, Apr 24, 2017 12:44 pm
info in Configuration issues by bpence, Feb 06, 2017 04:53 pm
info in Configuration issues by bpence, Jan 23, 2017 10:58 am
I really like all of the features it has. I mostly use it to telnet to my remote boxes that I oversee including the total control and a few packet shapers we have on our local isp. GOOD JOB !!! ;) -- Larry Thibodeaux - Internet Coordinator - CommuniComm Services