Back to product page
- Introduction
- License agreement
- Classes
- Enumerations
- Exceptions
- WeOnlyDo.Client.SSH
- Methods
- Properties
- AllocatePty
- Authentication
- Blocking
- Columns
- Command
- Compression
- DataOut
- DataReady
- Encryption
- EncryptionList
- ExitSignal
- ExitStatus
- FingerPrintType
- FIPS
- ForwardHost
- ForwardPort
- HMacList
- Hostname
- KeepAlives
- KeyExchangeList
- KeyFowarding
- Login
- Password
- Port
- PrivateKey
- Prompt
- Protocol
- ProxyHostname
- ProxyLogin
- ProxyPassword
- ProxyPort
- ProxyType
- RemoteIdentification
- Rows
- ShowStdErrorMessages
- State
- StripANSI
- Subsystem
- TerminalType
- Timeout
- Version
- Events
- How to get support?
WaitFor method
Waits and reads data until pattern is found.
Type
StringSyntax
- C#
- VB.NET
public String WaitFor(String Pattern);
The WaitFor(Pattern) syntax has these parts:
public String WaitFor(String Pattern, Int16 Timeout);
The WaitFor(Pattern,Timeout) syntax has these parts:
The WaitFor(Pattern) syntax has these parts:
Pattern | String that should be received to notify as command success. (exact text or regular expression) |
Return value | Data received while WaitFor was running. |
public String WaitFor(String Pattern, Int16 Timeout);
The WaitFor(Pattern,Timeout) syntax has these parts:
Pattern | String that should be received to notify as command success. (exact text or regular expression) |
Timeout | Seconds to wait for successful completion of the command. |
Return value | Data received while WaitFor was running. |
public Function WaitFor(ByVal Pattern As String) As String
The WaitFor(Pattern) syntax has these parts:
public Function WaitFor(ByVal Pattern As String, ByVal Timeout As Int16) As String
The WaitFor(Pattern,Timeout) syntax has these parts:
The WaitFor(Pattern) syntax has these parts:
Pattern | String that should be received to notify as command success. (exact text or regular expression) |
Return value | Data 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:
Pattern | String that should be received to notify as command success. (exact text or regular expression) |
Timeout | Seconds to wait for successful completion of the command. |
Return value | Data 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
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.