Writing data |
To send data via the SSH tunnel you must first obtain the System.IO.Stream associated with the tunnel. You can do this using the IpClientSsh.Stream property. Once you have obtained the Stream you can write data as you would to any other Stream.
Example
[C#]
// create login credentials
SshParameters sshParams = new SshParameters(sshHostname,sshUsername,sshPassword);
// create new SSH tunnel to specified POP3 server hostname and port
IpClientSsh ssh = new IpClientSsh(sshParams,popHostname, popPort);
// establish connection
ssh.Connect();
// get stream from tunnel
Stream stream = ssh.Stream;
// create StreamReader to read data from tunnel
System.IO.StreamReader reader = new StreamReader(stream);
// read welcome message from POP3 server and write to console
string line = reader.ReadLine();
Console.WriteLine(line);
// create StreamWriter to write data to tunnel
System.IO.StreamWriter writer = new StreamWriter(stream);
// write username to POP3 server
writer.WriteLine("USER username");
writer.Flush();
[VB]
' create login credentials
Dim sshParams As SshParameters = New SshParameters(sshHostname, sshUsername, sshPassword)
' create new SSH tunnel to specified POP3 server hostname and port
Dim ssh As IpClientSsh = New IpClientSsh(sshParams, popHostname, popPort)
' establish connection
ssh.Connect
' get stream from tunnel
Dim stream As Stream = ssh.Stream
' create StreamReader to read data from tunnel
Dim reader As System.IO.StreamReader = New StreamReader(stream)
' read welcome message from POP3 server and write to console
Dim Line As String = reader.ReadLine
Console.WriteLine(Line)
' create StreamWriter to write data to tunnel
Dim writer As System.IO.StreamWriter = New StreamWriter(stream)
' write username to POP3 server
writer.WriteLine("USER username")
writer.Flush