Link to home
Start Free TrialLog in
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
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


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
Avatar of HRMorton
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

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

Hi Chris,

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

Thanks
Heather
ivr.doc

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

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

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

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

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

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

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

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
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent, comprehensive suggestions, great patience with all my questions and didn't give up until it was solved.