|
Save the following VBScript code to a .vbs file on your machine.
Edit the file and modify the following variables:
g_szRemoteUserMachine:
your username
g_szRemoteDestination: destination folder on remote machine
g_szIdentityFile: identity file to use when connecting
~~~~~~~~~~~~~~~~~~~~~~~~
Begin DragAndDropSFXCL.vbs ~~~~~~~~~~~~~~~~~~~~~~
' DragAndDropSFXCL.vbs
'
' 06/09/2003
'
' This script demonstrates how to use drag and drop to transfer
' files to a pre-determined directory on a pre-determined
remote
' machine using a session that has been set up using the SecureFX
' UI.
'
' This example uses a session that has a saved password, and
does
' not delve into the specifics of how to use a session that
' requires a passphrase (for public key authentication), or
a
' password (for a session that does not have a password already
' saved). For more information about how you can use a private/
' public key for authentication with sfxcl.exe, contact
' support@vandyke.com
'
' Running this script without any arguments will present
' a dialog explaining setup and usage information.
Option Explicit
Dim g_objArgs, g_shell, g_fso
Set g_objArgs = WScript.Arguments
Set g_shell = CreateObject("WScript.Shell")
Set g_fso = CreateObject("Scripting.FileSystemObject")
Dim g_szSFXCLExePath, g_szTargetSessionPath,
g_szRemoteDestination
' Modify this variable to reflect the name
of the session to be
' used for connecting to the remote machine
g_szTargetSessionPath = "redhat"
' Modify this to reflect the path to the
destination folder on the
' remote machine
g_szRemoteDestination = "sfxcl-testing"
Dim g_szLogFile
g_szLogFile = "C:\Temp\sfxcl_log.txt"
' So that our log file doesn't grow too
big...
if g_fso.FileExists(g_szLogFile) Then g_fso.DeleteFile(g_szLogFile)
Main
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()
Dim szReg
szReg = "HKLM\Software\VanDyke\SecureFX\Install\Main
Directory"
g_szSFXCLExePath = g_shell.RegRead(szReg)
& "\sfxcl.exe"
If g_objArgs.Count
< 1 Then
ShowUsage
Exit Sub
End If
Dim nIndex, szArg,
szSourceArgs
For Each szArg
in g_objArgs
szSourceArgs
= szSourceArgs & " " & chr(34) & szArg
& chr(34)
Next
' For visual confirmation
that drag and drop is working
' correctly, uncomment the following
lines to display a
' message box with the arguments to
this script and then
' exit...
' Note that a MsgBox in VBScript can
only hold 256 characters
'MsgBox "Argument Count: "
& g_objArgs.Count & vbcrlf & _
' "------------------"
& vbcrlf & szSourceArgs
'Exit Sub
Dim szCommandLine,
szArgs, nResult
szArgs = szSourceArgs
& " " & _
"/S
" & chr(34) & g_szTargetSessionPath & chr(34)
& " " & _
g_szRemoteDestination
szCommandLine =
chr(34) & g_szSFXCLExePath & chr(34) & "
" & _
"/Log
" & chr(34) & g_szLogFile & chr(34) &
" " & szArgs
' For debugging,
or if you want to be really verbose, uncomment the
' following line
'If Not Continue(szCommandLine) Then
Exit Sub
' Now run the actual
command...
' "7" below is used to launch
sfxcl in a minimized cmd window.
' You could actually change this to
a 0 to hide the window entirely
nResult = g_shell.Run(szCommandLine,
7, True)
If nResult <>
0 Then
' Capture
some of the information from the Log file to display
' in the Error
message. This information might give some good
' hints as
to what might have gone wrong
Dim objLogFile,
szLogText, szLastLines
Set
objLogFile = g_fso.OpenTextFile(g_szLogFile)
szLogText
= objLogFile.ReadAll
'
Get the Last 6 lines of the log file and display them
Dim nPos,
nLine, szTimeTag
szTimeTag
= Year(Now) & "-" & NN(Month(Now)) &
"-" & NN(Day(Now))
For nLine
= 0 to 6
nPos
= InstrRev(szLogText, szTimeTag)
If
nPos = 0 Then Exit For
If
nLine > 0 Then szLastLines = Mid(szLogText, nPos) &
szLastLines
szLogText
= Left(szLogText, nPos - 1)
Next
szLastLines
= "[...]" & vbcrlf & szLastLines
MsgBox "Failed
to upload using the following command: " & vbCrlf
& _
chr(9)
& szCommandLine & vbCrlf & vbCrlf & _
"Error
code: " & nResult & vbcrlf & vbcrlf &
_
"Log
file details: " & vbcrlf & szLastLines
End If
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub ShowUsage()
MsgBox "DragAndDropSFXCL Usage:"
& chr(13) & chr(13) & _
"1. Create a session in SecureFX
that contains the" & vbcrlf & _
"connection information that
will be used for the" & vbcrlf & _
"target machine. You will probably
want to use this" & vbcrlf & _
"session to connect from within
SecureFX and save your" & vbcrlf & _
"password so that you will not
have to put any password" & vbcrlf & _
"information in this plain-text
script file." & _
vbcrlf & vbcrlf & _
"2. Create a Desktop shortcut
to this .vbs file." & vbCrlf & _
"If the .vbs extension is not
set to run wscript.exe" & vbcrlf & _
"automatically on your system,
create a shortcut with" & vbcrlf & _
"the path set to: " &
vbCrlf & _
chr(9) & "<path to wscript.exe>
<path to this .vbs file>" & _
vbCrlf & vbCrlf & _
"3. Drag And drop files and/or
folders from Windows" & vbcrlf & _
"Explorer onto the Desktop shortcut
for this .vbs file"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function Continue(szMsg)
Continue = True
If msgBox(szMsg, vbYesno) <>
vbYes Then Continue = False
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber)
' Normalizes a single digit number into a double-digit number
with a leading 0
If nNumber < 10 Then
NN = "0"
& nNumber
Else
NN = nNumber
End If
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~ End DragAndDropSFXCL.vbs
~~~~~~~~~~~~~~~~~~~~~~~
|