Recieve problem - WeOnlyDo Discussion board

Recieve problem (General questions)

by Maverick2004, Tuesday, February 15, 2005, 14:27 (7032 days ago)

I have a bit of a problem again, this time with the .Recieve method.
I logon to a Win2003 host with Telnet, and run a command. The output of this command, when run directly on the server, looks like below.

prosrm-2003:C:WINDOWSPrefetch, 1 browsable cycle(s)
5 browsable files of 5 total, 494 KB recoverable of 494 KB total

But when i run everything from within VB, the output looks like below.
It seems to miss the first few bytes, in this case prosrm-2003: .

C:WINDOWSPrefetch, 1 browsable cycle(s)
5 browsable files of 5 total, 494 KB recoverable of 494 KB total

Here´s my code, any suggestions as to why i get this behavior?
I don´t have any problems when i use SSH to Unix hosts.
[code]
With wodSSH1
.Disconnect
.HostName = server
.Login = user
.Password = psw
.Port = 23
.Protocol = Telnet
.TerminalType = dumb
.StripANSI = True
.Blocking = True
.Connect
.WaitFor regex:[C:>] , 5
.Prompt = regex:[C:>]
End With

If wodSSH1.DataReady > 0 Then wodSSH1.Receive
wodSSH1.Execute ( nsrim -X & vbCrLf)
temp = wodSSH1.Receive
[/code]
Cheers!
Maverick

Re: Recieve problem

by wodSupport, Tuesday, February 15, 2005, 14:30 (7032 days ago) @ Maverick2004

Maverick,

any chance we could connect to your system and see this internally? If so, please send us login details to techsupport@weonlydo.com

But I am sure (99.9 ) this is problem in your code :) Does this output belong to the command, or is part of command prompt?

Re: Recieve problem

by Maverick2004, Tuesday, February 15, 2005, 14:50 (7032 days ago) @ wodSupport

Damn you´re fast with your replys =)

Unfortunately, you cannot access the host from outside our firewall.
It would take a small miracle to get my boss to agree to that. =)
The output i pasted is passed to the command prompt by the command i run (i.e nsrim -X ), so i guess you could say it´s part of the command?
Are there any properties of the SSH component i could play around with, and if so, what would you suggest i try?

Cheers!
Maverick

Re: Recieve problem

by wodSupport, Tuesday, February 15, 2005, 14:53 (7032 days ago) @ Maverick2004

Problem with your posts is that it loses backslash, and I cannot be certain what is proper response. Can you please paste again exactly what is received from the server, but use double-backslash (which will appear as regular backslash here in forum).

What is expected to see *exactly* after you execute that command? are you sure you have consumed everything that was possibly in the buffer before calling Execute method?

Re: Recieve problem

by Maverick2004, Tuesday, February 15, 2005, 15:28 (7032 days ago) @ wodSupport

Below is what i recieve from the server:

C:\WINDOWS\Prefetch, 1 browsable cycle(s)
5 browsable files of 5 total, 494 KB recoverable of 494 KB total

What is expected, i.e what i get if i run the command
localy on the server, is this:

prosrm-2003:C:\WINDOWS\Prefetch, 1 browsable cycle(s)
5 browsable files of 5 total, 494 KB recoverable of 494 KB total

I´m not sure what you mean by consumed everything that was possibly in the buffer . I´m a bit of a newbie so bare with me. =)
With that in mind, what can i try before calling Execute?

Cheers!
Maverick

Re: Recieve problem

by wodSupport, Wednesday, February 16, 2005, 23:54 (7031 days ago) @ Maverick2004

Maverick,

I'm not sure why this happens. I suspect it's your app's issue since SSH protocol doesn't allow packets to be lost just like that (protocol violation error would occur). I wish I could duplicate that somehow to give you more info.

Re: Recieve problem

by Maverick2004, Thursday, February 17, 2005, 08:24 (7031 days ago) @ wodSupport

Hi again!
I did a small sample project, where i just use dir to list everything on c:\. This produces the same result, some info
is lost. Bare in mind that i´m using Telnet protocol when
connecting to Windows not SSH. When i use SSH for connecting
to Unix hosts, i do not have this problem. Below is *all* code
from ths sample:

[code]
Private Sub Command1_Click()
Dim temp As String

With wodSSH1
.Disconnect
.HostName = hostname
.Login = username
.Password = password
.Port = 23
.Protocol = Telnet
.TerminalType = dumb
.StripANSI = True
.Blocking = True
.Connect
.WaitFor regex:[C:>] , 5
.Prompt = regex:[C:>]
End With

If wodSSH1.DataReady > 0 Then wodSSH1.Receive
wodSSH1.Execute ( dir & vbCrLf)
temp = wodSSH1.Receive
End Sub
[/code]

Below is what i get when i just use dir directly on the server:


Volume in drive C has no label.
Volume Serial Number is 44FD-F6EB

Directory of C:Documents and SettingsAdministrator

2005-02-17 08:04 <DIR> .
2005-02-17 08:04 <DIR> ..
2005-02-17 07:54 <DIR> Desktop
2005-02-10 15:31 <DIR> Favorites
2005-02-10 15:31 <DIR> My Documents
2005-02-10 15:52 <DIR> Start Menu
2005-02-10 15:57 0 Sti_Trace.log
1 File(s) 0 bytes
6 Dir(s) 15 558 885 376 bytes free

This is what i recieve back when i run the code. As you can see,
info is lost in the beginning a well as at the end:


has no label.
Volume Serial Number is 44FD-F6EB

Directory of C:Documents and SettingsAdministrator

2005-02-17 08:04 <DIR> .
2005-02-17 08:04 <DIR> ..
2005-02-17 07:54 <DIR> Desktop
2005-02-10 15:31 <DIR> Favorites
2005-02-10 15:31 <DIR> My Documents
2005-02-10 15:52 <DIR> Start Menu
2005-02-10 15:57 0 Sti_Trace.log
1 File(s) 0 bytes
6 Dir(s) 15

Any suggestions to this? I´ve tried using both tty and dumb
as terminalType, i´ve tried StripANSI=False and True, i´ve tried
RecieveLine which also loses info and i get only has no label.
instead of Volume in drive C has no label. .

Cheers!
Maverick

Re: Recieve problem

by Maverick2004, Thursday, February 17, 2005, 08:26 (7031 days ago) @ Maverick2004

Sorry, forgot the double \ , but you get the point =)

Cheers!
Maverick

Re: Recieve problem

by wodSupport, Thursday, February 17, 2005, 23:22 (7030 days ago) @ Maverick2004

Ah, I see now. Did you try also to write result of Execute? It also returns something..... You may miss few bytes still (C:\) but those were possibly consmed with Prompt. Your prompt regex is bad I think, if I'm correct (and I'm NOT regex guru) you wait for ANY of C, :, \ so any of these causes execute to stop. If you use C:\ always as prompt, then you don't need regular expressions (remove regex: from Prompt proeprty).

Re: Recieve problem

by Maverick2004, Friday, February 18, 2005, 13:49 (7029 days ago) @ wodSupport

That did the trick! Thanks! =)

Another question, if i may ask this in the same post.
When my app launches, the user has to enter username
and password. These are later in the app used to connect
to the host and run the commands. How can i check that the
username and passwords are correct when the user enters them?
I need some form of code that just connects/disconnects to
check the username/password, and if it cannot connect with the supplied credentilas, provide an msgbox. I´ve tried using the
below code, but it doesn´t seem to fire, even if i enter the
wrong username/password?
[code]
With wodSSH1
.HostName = server
.Login = user
.Password = psw
.Port = 22
.Protocol = SSHAuto
.Connect
End With

Private Sub wodSSH1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
If ErrorCode > 0 Then
MsgBox Error & ErrorCode & has occured: & ErrorText, vbCritical, Connection error
Screen.MousePointer = vbDefault
Exit Sub
Else
wodSSH1.Disconnect
End If
End Sub
[/code]

Re: Recieve problem

by wodSupport, Friday, February 18, 2005, 15:56 (7029 days ago) @ Maverick2004

Maverick,

hmm, this cannot be true. Connected event *must* fire eventually, either with ErrorCode = 0 or with ErrorCode set to error that occured. Can you please double-check that? What about our samples, do they work? Is Connected event firing there?

Regards,
Kreso

Re: Recieve problem

by Maverick2004, Wednesday, February 23, 2005, 09:41 (7025 days ago) @ wodSupport

Did a short test with your example code without changing a thing,
but it does not seem to fire correctly there either. If the
connection fails, the code breaks att .Connect and presents a vb/windows error instead of my dialog.

Say if i enter a host that does not exsist, the code breaks with
Run-time rror '11001': Host not found . If the wodSSH1_Connected
event fired i should have gotten my dialog (below )instead, correct?
Or in your example case, CONNECT error: & ErrorText & vbCrLf
[code]
Private Sub wodSSH1_Connected(ByVal ErrorCode As Integer, ByVal ErrorText As String)
If ErrorCode <> 0 Then
MsgBox Error & ErrorCode & has occured: & ErrorText, vbCritical, Connection error
Screen.MousePointer = vbDefault
Exit Sub
Else
wodSSH1.Disconnect
End If
End Sub
[/code]
Cheers!
Maverick

Re: Recieve problem

by wodSupport, Wednesday, February 23, 2005, 12:21 (7024 days ago) @ Maverick2004

It's because Connection wasn't even initiated. Component couldn't resolve hostname you specified, and it failed immediately.

You can do On Error Resume Next and then check Err object after Connect to trap these errors.

Or, specify IP - it will work then.

Re: Recieve problem

by Maverick2004, Thursday, February 24, 2005, 16:17 (7023 days ago) @ wodSupport

Hi again!
Tried using the ip, which works fine if i use putty or some other telnet/ssh client. When i try your example code i still get connected message even though i enter wrong username and password. I just ran your example code straight out of the box , which is with Telnet. With SSH it seems to work, although i´m having some access violation problems in my own code now... =) Anyway, the question is why the example code doesn´t trigger on wrong username/password with Telnet?

Cheers!
Maverick

Re: Recieve problem

by wodSupport, Thursday, February 24, 2005, 20:42 (7023 days ago) @ Maverick2004

Maverick,

it's because in Telnet protocol component cannot be smart enough to determine if connection was successful or not. It did establish connection, it did send login and password - but it cannot know server's response. So, you can call Receive method to determine server's response and see what it said. If it returned 'denied', 'failed' etc.. then it probably failed. You can do it - but we cannot in the component since we must make more generic interface, where clients perhaps connect to some automated services, BBSes etc.. So, it's better to let you handle this.

Re: Recieve problem

by Maverick2004, Monday, February 28, 2005, 14:16 (7019 days ago) @ wodSupport

Thanks, got it working now by checking the receive output. =)

Cheers!
Maverick