Back to product page

WaitFor method


Waits and reads data until pattern is found.

Type

String

Syntax

  • C#
  • VB.NET
public String WaitFor(String Pattern);
The WaitFor(Pattern) syntax has these parts:
PatternString that should be received to notify as command success. (exact text or regular expression)
Return valueData received while WaitFor was running.

public String WaitFor(String Pattern, Int16 Timeout);
The WaitFor(Pattern,Timeout) syntax has these parts:
PatternString that should be received to notify as command success. (exact text or regular expression)
TimeoutSeconds to wait for successful completion of the command.
Return valueData received while WaitFor was running.

public Function WaitFor(ByVal Pattern As String) As String
The WaitFor(Pattern) syntax has these parts:
PatternString that should be received to notify as command success. (exact text or regular expression)
Return valueData received while WaitFor was running.

public Function WaitFor(ByVal Pattern As String, ByVal Timeout As Int16) As String
The WaitFor(Pattern,Timeout) syntax has these parts:
PatternString that should be received to notify as command success. (exact text or regular expression)
TimeoutSeconds to wait for successful completion of the command.
Return valueData received while WaitFor was running.

Remarks

WaitFor method will receive data from the server until specified Pattern is found, or timeout expires.

NOTE: this method works only when Blocking property is set to True.

Very common way for using WaitFor method is to read all data that servers sends us upon connection. Usually zou will know exactly what you need to receive, so you can use this command to help you, like this:
 
Ssh1.Hostname = "yourhost";
Ssh1.Login = "tester";
Ssh1.Password = "weonlydo";
Ssh1.Protocol = WeOnlyDo.Client.SSH.SupportedProtocols.SSHAuto;
Ssh1.Blocking = true;
Ssh1.Connect();
 
Console.Write(Ssh1.WaitFor("joe@yourhost"));
 

This sample will block until 'joe@yourhost' is found within received text. If it's not found in reasonable time (until timeout expires), you will still be able to call Receive to obtain received data.

Note - this command internally disables PromptReceived event and DataReceived event since it's taking control on what's received from the server.

As mentioned above, you can provide regular expression to be set as expected response. You should prepend Pattern argument with regex: text so wodSSH.NET knows you are using regular expression. For example, you can use it like this:
 
Console.Write (Ssh1.WaitFor("regex:[\\$%#>] $", 10));
 

above regular expression will match when:
  • $, %, #, or > found
  • space
  • end of line
typically, our previous sample joe@somehost:~$ does match above regex. But, hey, feel free to use something more complex such as:
 
Console.Write(Ssh1.WaitFor("regex:[a-zA-z0-9]+@[a-zA-z0-9]+:[a-zA-z0-9~/]+[\\$%#>] $", 10));
 

or using extended PERL syntax
 
Console.Write(Ssh1.WaitFor("regex:\\w+@\\w+:\\S+\\$ $", 10));
 

just don't forget to put 'regex:' text in front of regular expression, otherwise wodSSH.NET will search for exact match of specified pattern.

Platforms

Windows