本文整理汇总了C#中SshClient.AddForwardedPort方法的典型用法代码示例。如果您正苦于以下问题:C# SshClient.AddForwardedPort方法的具体用法?C# SshClient.AddForwardedPort怎么用?C# SshClient.AddForwardedPort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SshClient
的用法示例。
在下文中一共展示了SshClient.AddForwardedPort方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddForwardedPortTest
public void AddForwardedPortTest()
{
ConnectionInfo connectionInfo = null; // TODO: Initialize to an appropriate value
SshClient target = new SshClient(connectionInfo); // TODO: Initialize to an appropriate value
ForwardedPort port = null; // TODO: Initialize to an appropriate value
target.AddForwardedPort(port);
Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
示例2: Test_AddForwardedPort_Remote_Hosts_Are_Null
public void Test_AddForwardedPort_Remote_Hosts_Are_Null()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = client.AddForwardedPort<ForwardedPortRemote>(null, 8080, null, 80);
client.Disconnect();
}
}
示例3: Test_AddForwardedPort_Local_Hosts_Are_Empty
public void Test_AddForwardedPort_Local_Hosts_Are_Empty()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = client.AddForwardedPort<ForwardedPortLocal>(string.Empty, 8080, string.Empty, 80);
client.Disconnect();
}
}
示例4: Test_AddForwardedPort_Invalid_PortNumber
public void Test_AddForwardedPort_Invalid_PortNumber()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = client.AddForwardedPort<ForwardedPortRemote>("localhost", IPEndPoint.MaxPort+1, "www.renci.org", IPEndPoint.MaxPort+1);
client.Disconnect();
}
}
示例5: Test_ForwardedPortRemote
public void Test_ForwardedPortRemote()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
#region Example SshClient AddForwardedPort Start Stop ForwardedPortRemote
client.Connect();
var port = new ForwardedPortRemote(8082, "www.cnn.com", 80);
client.AddForwardedPort(port);
port.Exception += delegate(object sender, ExceptionEventArgs e)
{
Console.WriteLine(e.Exception.ToString());
};
port.Start();
Thread.Sleep(1000 * 60 * 20); // Wait 20 minutes for port to be forwarded
port.Stop();
#endregion
}
Assert.Inconclusive("TODO: Implement code to verify target");
}
示例6: Arrange
protected void Arrange()
{
_connectionInfo = new ConnectionInfo("host", "user", new NoneAuthenticationMethod("userauth"));
var sequence = new MockSequence();
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
_forwardedPortMock = new Mock<ForwardedPort>(MockBehavior.Strict);
_serviceFactoryMock.InSequence(sequence).Setup(p => p.CreateSession(_connectionInfo)).Returns(_sessionMock.Object);
_sessionMock.InSequence(sequence).Setup(p => p.Connect());
_forwardedPortMock.InSequence(sequence).Setup(p => p.Start());
_sessionMock.InSequence(sequence).Setup(p => p.OnDisconnecting());
_forwardedPortMock.InSequence(sequence).Setup(p => p.Stop());
_sessionMock.InSequence(sequence).Setup(p => p.Dispose());
_sshClient = new SshClient(_connectionInfo, false, _serviceFactoryMock.Object);
_sshClient.Connect();
_sshClient.AddForwardedPort(_forwardedPortMock.Object);
_forwardedPortMock.Object.Start();
}
示例7: Test_PortForwarding_Remote
public void Test_PortForwarding_Remote()
{
// ******************************************************************
// ************* Tests are still in not finished ********************
// ******************************************************************
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = new ForwardedPortRemote(8082, "www.renci.org", 80);
client.AddForwardedPort(port1);
port1.Exception += delegate(object sender, ExceptionEventArgs e)
{
Assert.Fail(e.Exception.ToString());
};
port1.Start();
var boundport = port1.BoundPort;
System.Threading.Tasks.Parallel.For(0, 5,
//new ParallelOptions
//{
// MaxDegreeOfParallelism = 1,
//},
(counter) =>
{
var cmd = client.CreateCommand(string.Format("wget -O- http://localhost:{0}", boundport));
var result = cmd.Execute();
var end = DateTime.Now;
Debug.WriteLine(string.Format("Length: {0}", result.Length));
}
);
Thread.Sleep(1000 * 100);
port1.Stop();
}
}
示例8: Test_PortForwarding_Local_Stop_Hangs_On_Wait
public void Test_PortForwarding_Local_Stop_Hangs_On_Wait()
{
using (var client = new SshClient(Resources.HOST, Int32.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = client.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.google.com",80);
port1.Exception += delegate(object sender, ExceptionEventArgs e)
{
Assert.Fail(e.Exception.ToString());
};
port1.Start();
bool hasTestedTunnel = false;
System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state)
{
try
{
var url = "http://www.google.com/";
Debug.WriteLine("Starting web request to \"" + url + "\"");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Assert.IsNotNull(response);
Debug.WriteLine("Http Response status code: " + response.StatusCode.ToString());
response.Close();
hasTestedTunnel = true;
}
catch (Exception ex)
{
Assert.Fail(ex.ToString());
}
});
// Wait for the web request to complete.
while(!hasTestedTunnel)
{
System.Threading.Thread.Sleep(1000);
}
try
{
// Try stop the port forwarding, wait 3 seconds and fail if it is still started.
System.Threading.ThreadPool.QueueUserWorkItem(delegate(object state)
{
Debug.WriteLine("Trying to stop port forward.");
port1.Stop();
Debug.WriteLine("Port forwarding stopped.");
});
System.Threading.Thread.Sleep(3000);
if (port1.IsStarted)
{
Assert.Fail("Port forwarding not stopped.");
}
}
catch (Exception ex)
{
Assert.Fail(ex.ToString());
}
client.Disconnect();
Debug.WriteLine("Success.");
}
}
示例9: AddForwardedPort_NeverConnected
public void AddForwardedPort_NeverConnected()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, "invalid password"))
{
var port = new ForwardedPortLocal(50, "host", 8080);
try
{
client.AddForwardedPort(port);
Assert.Fail();
}
catch (SshConnectionException ex)
{
Assert.IsNull(ex.InnerException);
Assert.AreEqual("Client not connected.", ex.Message);
}
}
}
示例10: Test_PortForwarding_Local
public void Test_PortForwarding_Local()
{
using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
{
client.Connect();
var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
client.AddForwardedPort(port1);
port1.Exception += delegate(object sender, ExceptionEventArgs e)
{
Assert.Fail(e.Exception.ToString());
};
port1.Start();
System.Threading.Tasks.Parallel.For(0, 100,
//new ParallelOptions
//{
// MaxDegreeOfParallelism = 20,
//},
(counter) =>
{
var start = DateTime.Now;
var req = HttpWebRequest.Create("http://localhost:8084");
using (var response = req.GetResponse())
{
var data = ReadStream(response.GetResponseStream());
var end = DateTime.Now;
Debug.WriteLine(string.Format("Request# {2}: Length: {0} Time: {1}", data.Length, (end - start), counter));
}
}
);
}
}