wodSSH in C++ Builder - WeOnlyDo Discussion board

wodSSH in C++ Builder (General questions)

by Ryan Crosby, Wednesday, August 31, 2005, 21:51 (7023 days ago)

Hi,

I'm testing wodSSH for a client application I'm building with builder 6. I need the use of the SSH2 protocol, and I can connect to the remote server, but when I try to use the execute method to run su and further commands I get the following error:

this->Execute(Command, Prompt, Timeout, (BSTR*)&retval)) Error: 800A7548(-216798264) @ C:Program FilesBorlandCBuilder6ImportsWODSSHLib_TLB.h/685
Press[Y]es to Terminate, [N]o to Continue and [C]ancel to Debug.

I'm trying to get the program to wait for certain prompts at the remote end and fire commands once it reaches that point, but it appears to timeout immediately without waiting to see if the data is received. Any ideas what would cause this to happen? Thanks...


Ryan

Re: wodSSH in C++ Builder

by wodSupport, Wednesday, August 31, 2005, 21:58 (7023 days ago) @ Ryan Crosby

Ryan,

yes, COM error 800A7548 should be checked by using last word fro it - hex(7548) = dec(30024) = Only available in Blocking mode .

Error says it all. You can use WaitFor (or Execute) only when Blocking is set to true.

Hope it helps.

Re: wodSSH in C++ Builder

by Ryan Crosby, Wednesday, August 31, 2005, 23:29 (7023 days ago) @ wodSupport

Hi,

Thanks for the help, I am only using the trial version right now to see if I can get it to do what I want it to do so I don't know much about it. I have only been programming for about a month and a half as well, so I appreciate any help that I can get trying to learn. I have been a help file hero trying to learn how to use wodSSH, as well as the built in functions to the C++ Builder VCL. I noticed in the help file it mentions referencing & vbLf to process a line feed after the BSTR you send to the server. I'm assuming you must do this as well in C++ using either
or
? As far as creating an app that only has preset functions and no user interactive input on the server is it recommended to use either the Execute() or WaitFor() method and not utilize the prompt received event. The reason I ask is because the prompt for the server changes once I use the su command login as root- from ending in $ to #. I thought about trying to use a static in counter for figuring out which command to fire, but I can't seem to initialize one in C++ Builder. Any advice on how to tackle that would be great, thanks again for the help!!


Ryan

Re: wodSSH in C++ Builder

by wodSupport, Wednesday, August 31, 2005, 23:59 (7023 days ago) @ Ryan Crosby

Ryan,

please write smaller posts, or try to divide them in sections next time, ok? This one is VERY HARD to answer since I have no idea what you actually asked.

Let me *try* to answer:

VbLf is \n in C++, so yes, this is linefeed

Problem with # and $ can usually be easily solved by using regular expression syntax in Waitfor pattern. If you check out helpfile for Waitfor method, you will see we propose there to use regex:[\$ #>] $ - that should match both $ and # when at end of the line.

Hope this helps.

Re: wodSSH in C++ Builder

by Ryan Crosby, Thursday, September 01, 2005, 01:35 (7023 days ago) @ wodSupport

Hi,

Sorry about that, the only problem with that is if I place any code to run in the prompt received event, there is no way to distinguish which prompt I am at, and which function I want to call.

If I use the regex: call for $ and #, then I can run a function the first time, but when the event is fired again, it will try to run the same command again which won't work. Does that make any sense? Basically I need it to be able to select a function based on the number of times the prompt has been reached...

Ryan

Re: wodSSH in C++ Builder

by wodSupport, Thursday, September 01, 2005, 01:39 (7023 days ago) @ Ryan Crosby

Ryan,

there is a way to distinguish them - use your own counter if you wish. Or find some other logic.

Question 'how' goes beyond our support since we can only help with the protocol and component, but cannot really help your specific case - since we would need to duplicate and know your exact specific tasks.

Re: wodSSH in C++ Builder

by Ryan Crosby, Thursday, September 01, 2005, 16:47 (7022 days ago) @ wodSupport

Thanks, I got it going somewhat, now I'm just having trouble getting it to recognize BSTR sequences it should be returning from the remote side, but at least I have it processing at this point. I'll have to figure that one out.

Ryan

Re: wodSSH in C++ Builder

by wodSupport, Thursday, September 01, 2005, 16:49 (7022 days ago) @ Ryan Crosby

Ryan,

what does it mean 'recognize BSTR sequences'? If you need to convert them to/from LPSTR you can use WideCharToMultiByte and MultiTypeToWideChar, but I'm quite sure BCB has some internal classes for that.

Re: wodSSH in C++ Builder

by Ryan Crosby, Thursday, September 01, 2005, 17:25 (7022 days ago) @ wodSupport

The Execute() method calls for tagVARIANT, so I'm converting expected AnsiStrings to a VARIANT like this:

VARIANT v1;
VariantInit(&v1);
v1.vt = VT_BSTR;
v1.bstrVal = WideString(SomeAnsiString);

SSH->Execute(wchar_t *, v1, tagVARIANT Timeout);

Then I'm using Execute() to find this next prompt, and then I clear the VARIANT when I'm done with it. Does this look right?

Re: wodSSH in C++ Builder

by wodSupport, Thursday, September 01, 2005, 17:29 (7022 days ago) @ Ryan Crosby

I don't know, is WideString same as BSTR?

Re: wodSSH in C++ Builder

by Ryan Crosby, Thursday, September 01, 2005, 17:43 (7022 days ago) @ wodSupport

Hello,

WideString(SomeAnsiString) returns a string of type wchar_t *, and that's the same type as bstrVal, so I'm not sure why it's not working.


Ryan

Re: wodSSH in C++ Builder

by wodSupport, Thursday, September 01, 2005, 17:44 (7022 days ago) @ Ryan Crosby

Ryan,

can you create EXE which I could run here and send it to techsupport@weonlydo.com ? I can check this out.

Re: wodSSH in C++ Builder

by Ryan Crosby, Thursday, September 01, 2005, 18:33 (7022 days ago) @ wodSupport

Hi,

I don't actually have an EXE built for this because I'm only seeing if I can get it to work.

What has me baffled is that it gets part way through the program, and then times out a second call to Execute() either caused by the String I send, or the prompt I'm trying to match, so I know the method seems to be working.


Ryan

Re: wodSSH in C++ Builder

by Ryan, Wednesday, September 07, 2005, 17:11 (7016 days ago) @ Ryan Crosby

I figured out what the problem was, the conversion from Ansistring to Widestring was not being completed properly by my compiler, I used a different method for declaring my Widestring variables and it worked like a charm...


Ryan

Re: wodSSH in C++ Builder

by wodSupport, Wednesday, September 07, 2005, 17:53 (7016 days ago) @ Ryan

Ryan,

oh, too bad.. Well, good for you. But I spent few days making sample for you and now you don't need it anymore.. Ghee...

Anyone else need it? :)

I'll just put it into regular setup package, it may come handy..

Re: wodSSH in C++ Builder

by Ryan, Wednesday, September 07, 2005, 17:56 (7016 days ago) @ wodSupport

Well if you made a sample I will surely take it, because that is only going to strengthen my understanding of the product, so you didn't do it for no reason... should I give you my email for that?

Re: wodSSH in C++ Builder

by wodSupport, Thursday, September 08, 2005, 00:45 (7016 days ago) @ Ryan

Just get newest install package, we have included it there.

Regards,
Kreso