In this tip you'll learn how to use SFXCL (a command-line file transfer utility included with SecureFX® for Windows), a VBScript, and a desktop shortcut to create a convenient way to securely upload files to a remote sever by simply dragging and dropping right from Windows Explorer.
Note: This tip is for use with SecureFX for Windows.
If you're a SecureFX for Windows user taking advantage of the SFXCL command-line SFTP utility for secure file transfers, it's often inconvenient to bring up a command prompt and type in the command and the full path to the folder or files you want to transfer each time you need to upload.
Ever wish you had the ability to securely upload a file to a remote sever by simply dragging and dropping right from Windows Explorer?
In this tip, we show you how you can combine SFXCL, a VBScript, and a desktop shortcut to allow drag and drop SFTP transfers to a folder on a remote machine.
These are the steps to take:
Once you have successfully completed steps 1 and 2, you should be able to drag and drop both files and folders from Explorer onto the Desktop shortcut and the selected files and folders will be uploaded to the specified folder on the remote machine indicated within the script.
Here is the code to create a VBScript, DragAndDropSFXCL.vbs:
Save the following VBScript code to a .vbs file on your machine. Edit the file and modify the following variables:
g_szRemoteDestination: destination folder on remote machine
g_szIdentityFile: identity file to use when connecting
Begin DragAndDropSFXCL.vbs ~~~~~~~~~~~~~~~~~~~~~~
' 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
' 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
' Running this script without any arguments will present
' a dialog explaining setup and usage information.
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"
g_szLogFile = "C:\Temp\sfxcl_log.txt"
' So that our log file doesn't grow too
if g_fso.FileExists(g_szLogFile) Then g_fso.DeleteFile(g_szLogFile)
szReg = "HKLM\Software\VanDyke\SecureFX\Install\Main Directory"
g_szSFXCLExePath = g_shell.RegRead(szReg) & "\sfxcl.exe"
< 1 Then
Dim nIndex, szArg, szSourceArgs
For Each szArg
szSourceArgs = szSourceArgs & " " & chr(34) & szArg & chr(34)
' 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
' Note that a MsgBox in VBScript can only hold 256 characters
'MsgBox "Argument Count: " & g_objArgs.Count & vbcrlf & _
' "------------------" & vbcrlf & szSourceArgs
Dim szCommandLine, szArgs, nResult
szArgs = szSourceArgs
& " " & _
"/S " & chr(34) & g_szTargetSessionPath & chr(34) & " " & _
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
' "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 <>
' 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
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)
= "[...]" & 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
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"
Continue = True
If msgBox(szMsg, vbYesno) <> vbYes Then Continue = False
' Normalizes a single digit number into a double-digit number with a leading 0
If nNumber < 10 Then
NN = "0" & nNumber
NN = nNumber
'~~~~~~~~~~~~~~~~~~~~~~~~~~~ End DragAndDropSFXCL.vbs ~~~~~~~~~~~~~~~~~~~~~~~
Here you can control cookies using the checkboxes below. Some cookies are essential for the use of our website and cannot be disabled. Others provide a convenience to the user and, if disabled, may reduce the ease of use of our site. Finally, some cookies provide anonymous analytic tracking data that help us provide the user with a richer browsing experience. You can elect to disable these cookies as well.