本文整理匯總了C#中Tamir.SharpSsh.jsch.Session.setHost方法的典型用法代碼示例。如果您正苦於以下問題:C# Session.setHost方法的具體用法?C# Session.setHost怎麽用?C# Session.setHost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Tamir.SharpSsh.jsch.Session
的用法示例。
在下文中一共展示了Session.setHost方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Connect
public static void Connect()
{
try
{
var jsch = new JSch();
_session = jsch.getSession(Settings.SSHUsername, Settings.SSHHost, Settings.SSHPort);
_session.setHost(Settings.SSHHost);
_session.setPassword(Settings.SSHPassword);
UserInfo ui = new MyUserInfo(Settings.SSHPassword);
_session.setUserInfo(ui);
_session.connect();
int port;
if (!int.TryParse(Settings.Port, out port))
port = 3306;
_session.setPortForwardingL(Settings.SSHLocalPort, "localhost", port);
if (!_session.isConnected())
Enabled = false;
}
catch (Exception ex)
{
Enabled = false;
Trace.WriteLine(ex.Message + " at ssh connect.");
Disconnect();
}
}
示例2: jschServer
/// <summary>
/// This class creates a jsch instance using the host that user wants. This makes it possible to
/// forward the MySql Database port to a user's local port.
/// </summary>
public string jschServer(string host, string user, string password)
{
try
{
// Create a new JSch instance
JSch jsch = new JSch();
// Saves the info to make other sessions
this.host = host;
this.user = user;
this.password = password;
// Create a new SSH session
session = jsch.getSession(user, password, port);
session.setHost(host); ;
session.setPassword(password);
// Creates a userinfo instance to pass into the session
UserInfo ui = new MyUserInfo();
session.setUserInfo(ui);
session.connect();
return null;
}
catch (Exception ex)
{
session.disconnect();
return ex.Message;
}
}
示例3: OnStart
protected override void OnStart(string[] args)
{
bool ontWorkerInstantiated = false;
if (Repository.Configuration.Processes == null)
return;
if (Repository.Configuration.Database.SSH.Enabled)
{
try
{
//Create a new SSH session
_jsch = new JSch();
_sshSession = _jsch.getSession(
Repository.Configuration.Database.SSH.UserID,
Repository.Configuration.Database.SSH.Host,
Repository.Configuration.Database.SSH.Port);
_sshSession.setHost(Repository.Configuration.Database.SSH.Host);
_sshSession.setPassword(Repository.Configuration.Database.SSH.Password);
UserInfo ui = new JschUserInfo();
_sshSession.setUserInfo(ui);
// Connect
_sshSession.connect();
//Set port forwarding on the opened session
_sshSession.setPortForwardingL(
Repository.Configuration.Database.SSH.LocalPort,
Repository.Configuration.Database.SSH.ForwardingHost,
Repository.Configuration.Database.SSH.RemotePort);
if (!_sshSession.isConnected())
throw new Exception("SSH Session did not connect.");
}
catch (Exception ex)
{
EventLogWriter.WriteError("Could not start due to SSH Error:\n{0}", ex);
return;
}
}
foreach (TextMinerServiceSettingsProcess process in Repository.Configuration.Processes)
{
if (!process.Enabled)
continue;
switch (process.Type)
{
case ProcessType.OntologySubsetWorker:
{
// Only one thread of this type allowed
if (ontWorkerInstantiated == true)
continue;
process.Worker = new Worker.OntologySubset(process.PollingInterval, process.Timeout, process.ResponseTimeout);
ontWorkerInstantiated = true;
break;
}
case ProcessType.PubMed:
{
process.Worker = new Worker.PubMed(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
break;
}
case ProcessType.Pubget:
{
process.Worker = new Worker.Pubget(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
break;
}
case ProcessType.ClinicalTrialsGov:
{
process.Worker = new Worker.ClinicalTrialsGov(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
break;
}
default:
{
continue;
}
}
process.Thread = new Thread(new ThreadStart(process.Worker.Start));
process.Thread.Start();
}
}
示例4: OpenSSH
protected void OpenSSH()
{
try
{
//Create a new SSH session
_jsch = new JSch();
_sshSession = _jsch.getSession(
Settings.SSHUserID,
Settings.SSHHost,
int.Parse(Settings.SSHPort));
_sshSession.setHost(Settings.SSHHost);
_sshSession.setPassword(Settings.SSHPassword);
UserInfo ui = new JschUserInfo();
_sshSession.setUserInfo(ui);
// Connect
_sshSession.connect();
//Set port forwarding on the opened session
_sshSession.setPortForwardingL(
int.Parse(Settings.SSHLocalPort),
Settings.SSHForwardingHost,
int.Parse(Settings.SSHRemotePort));
if (!_sshSession.isConnected())
throw new Exception("SSH Session did not connect.");
}
catch (Exception ex)
{
MessageBox.Show(string.Format("Could not start due to SSH Error:\n{0}", ex));
return;
}
}
示例5: getSession
public Session getSession(String username, String host, int port)
{
Session s=new Session(this);
s.setUserName(username);
s.setHost(host);
s.setPort(port);
pool.Add(s);
return s;
}
示例6: Connect
public static bool Connect(string thost,string tuser,string tpass,string tport)
{
try
{
JSch jsch = new JSch();
host = thost;
user = tuser;
pass = tpass;
sshPort = Convert.ToInt32(tport);
session = jsch.getSession(user, host, sshPort);
session.setHost(host);
session.setPassword(pass);
UserInfo ui = new MyUserInfo();
session.setUserInfo(ui);
session.connect();
session.setPortForwardingL(lPort, "127.0.0.1", rPort);
return true;
}
catch (Exception ex)
{
error = ex;
return false;
}
}