Avatar of HRMorton
HRMorton
 asked on

Call Tunnelier Interface from vbscript

Hi,
I'm trying to use a program called Tunnelier to do secure file transfer. I want to invoke Tunnelier from a vbscript.
The command I've tried is :-
     objShell.Run chr(34) &"c:\program files\Bitvise Tunnelier sftpc.exe -profile=c:\sftpc_profiles\Eckoh.tlp -cmd=cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b"

The file ivraddsupdcsv020305 exists on a directory called /home/sx3user/test and I want to download it to my C:/IVR directory.

When I run the script I get an error that the system can not find the file specified.
Any ideas as to where I'm going wrong would be much appreciated.

Thanks
Heather
VB Script

Avatar of undefined
Last Comment
HRMorton

8/22/2022 - Mon
Chris Dent


Hey,

Probably because of the extra ", the Chr(34) you've got in there.

The quotes can be escaped with another quote, meaning "" gives you one quote in a string. So if we want the main path in quotes we would do:

objShell.Run """c:\program files\Bitvise Tunnelier sftpc.exe"" -profile=c:\sftpc_profiles\Eckoh.tlp -cmd=cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b"

It can also be written like this if you prefer to stick with concatenating the Chr(34)'s:

objShell.Run Chr(34) & "C:\Program Files\Bitvise Tunnelier sftpc.exe" & Chr(34) & " -profile=c:\sftpc_profiles\Eckoh.tlp -cmd=cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b"

If you do it the second way remember that you'll need that space after you restart the string or it might break the command anyway.

In all cases it's a single line, no line breaks included in the command. It would perhaps be neater to break the line with a _. For example:

objShell.Run """c:\program files\Bitvise Tunnelier sftpc.exe""" &_
    " -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b"

HTH

Chris
HRMorton

ASKER
Hi Chris,

Thanks for that, I tried the above command, unfortunately it doesn't seem to like the spaces in the directory names so I moved the sftpc.exe file to my c: drive.  It now runs without complaint, but I still do not get the file I'm expecting in the C:\IVR directory.  Have searched the rest of my c: drive and it's not there either.

If I put the command in the cmd window it seems to work fine.

Any ideas where I'm going wrong would be appreciated.

Thanks
Heather
Chris Dent


Hi Heather,

.Run will hide the program responses from us. If we change it a bit we can make it show us any return from the command.

You'll need to fix the path in this one again.

Chris
strCommand = """c:\program files\Bitvise Tunnelier\sftpc.exe""" &_
    " -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b" 
 
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec(strCommand)
Set objStdOut = objScriptExec.StdOut
 
WScript.Echo objStdOut.ReadAll

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
HRMorton

ASKER
Hi Chris,

Changed the code and got the output as per the attached document.

Thanks
Heather
ivr.doc
Chris Dent


Okay so it's just command usage.

What, exactly, do you type on the command line when you run it normally?

I suspect all you'll have to do is enclose the commands you're passing in quotes (as below). I assume -o and -b are commands you're running inside sftpc instead of parameters you use when you run it?

Chris
strCommand = """c:\program files\Bitvise Tunnelier\sftpc.exe""" &_
    " -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=""cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b"""
 
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec(strCommand)
Set objStdOut = objScriptExec.StdOut
 
WScript.Echo objStdOut.ReadAll

Open in new window

HRMorton

ASKER
Hi,

If I enclose the cmd in double set of quotes, it opens a cmd window but goes no further, I have to
close the cmd window.

Running the command from cmd works perfectly as per the attached.

Thanks
Heather
ivr1.doc
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Chris Dent


Ahh okay, cool, the command is enclosed in quotes.

Is it not just missing "exit" from the command list (added below)? Without that the command would never terminate, leaving you with the window open.

Chris


strCommand = """c:\program files\Bitvise Tunnelier\sftpc.exe""" &_
    " -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=""cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b; exit"""
 
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec(strCommand)
Set objStdOut = objScriptExec.StdOut
 
WScript.Echo objStdOut.ReadAll

Open in new window

HRMorton

ASKER
Hi,

Unfortunately not, the exit does not seem to change what is happening.
When I close the DOS window that appears to be hanging I get another message box.

Thanks
Heather
ivr2.doc
Chris Dent


Okay, doesn't look like it's passing the commands, helpful...

Add this line into the VbScript if you could please:

WScript.Echo strCommand

Should go in as below. Just want to make sure it's passing the full command.

Chris


strCommand = """c:\program files\Bitvise Tunnelier\sftpc.exe""" &_
    " -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=""cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b; exit"""
 
WScript.Echo strCommand
 
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec(strCommand)
Set objStdOut = objScriptExec.StdOut
 
WScript.Echo objStdOut.ReadAll

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
HRMorton

ASKER
Hi,
Does seem to be the full command as per the attached document, if I take the command and input it directly into DOS it works fine.

Thanks
Heather

ivr3.doc
Chris Dent


How annoying...

Lets swap back to the Run Method to see if it likes that one a little more now the command is correct.

Chris
strCommand = "c:\sftpc.exe -profile=c:\sftpc_profiles\Eckoh.tlp" &_
    " -cmd=""cd /Test; get ivraddsupdcsv020305 C:/IVR -o -b; exit"""
 
Set objShell = CreateObject("WScript.Shell")
objShell.Run strCommand

Open in new window

HRMorton

ASKER
Hi Chris,

You're a genius, the run method worked perfectly, I now have the file transferred.
Thanks for all the help, and the patience to go thru it all. I wish I'd allocated more points so I could
attribute them to you.

Can I be really cheeky and ask one more question, is there a way to hide the DOS window coming up now that I know it's working ?

Thanks
Heather
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
HRMorton

ASKER
Excellent, comprehensive suggestions, great patience with all my questions and didn't give up until it was solved.