本文整理汇总了C#中Tamir.SharpSsh.jsch.JSch.addIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# JSch.addIdentity方法的具体用法?C# JSch.addIdentity怎么用?C# JSch.addIdentity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tamir.SharpSsh.jsch.JSch
的用法示例。
在下文中一共展示了JSch.addIdentity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public void Connect()
{
InitVAHInfo();
try
{
JSch jsch = new JSch();
_ssn = jsch.getSession(_usr, _hip, _hp);
System.Collections.Hashtable hashConfig = new Hashtable();
hashConfig.Add("StrictHostKeyChecking", "No");
_ssn.setConfig(hashConfig);
jsch.addIdentity(_ppk);
_ssn.connect();
if (_ssn.isConnected())
{
Console.WriteLine("Log Successfully.");
}
else
{
Console.WriteLine("Log failed.");
}
}
catch (Tamir.SharpSsh.jsch.JSchException jschex)
{
Console.WriteLine(jschex.Message);
}
catch (Exception anyex)
{
Console.WriteLine(anyex.Message);
}
}
示例2: RunExample
public static void RunExample(String[] arg)
{
try
{
JSch jsch=new JSch();
//Get the "known hosts" filename from the user
Console.WriteLine("Please choose your private key file...");
String file = InputForm.GetFileFromUser("Choose your privatekey(ex. ~/.ssh/id_dsa)");
Console.WriteLine("You chose "+file+".");
//Add the identity file to JSch
jsch.addIdentity(file);
//Prompt for username and server host
Console.WriteLine("Please enter the user and host info at the popup window...");
String host = InputForm.GetUserInput
("Enter [email protected]",
Environment.UserName+"@localhost");
String user=host.Substring(0, host.IndexOf('@'));
host=host.Substring(host.IndexOf('@')+1);
//Create a new SSH session
Session session=jsch.getSession(user, host, 22);
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
//Connect to remote SSH server
session.connect();
//Open a new Shell channel on the SSH session
Channel channel=session.openChannel("shell");
//Redirect standard I/O to the SSH channel
channel.setInputStream(Console.OpenStandardInput());
channel.setOutputStream(Console.OpenStandardOutput());
//Connect the channel
channel.connect();
//Wait till channel is closed
while(!channel.isClosed())
{
System.Threading.Thread.Sleep(500);
}
//Disconnect from remote server
channel.disconnect();
session.disconnect();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
示例3: loadIdentity
private static void loadIdentity(JSch sch, FileInfo priv)
{
if (!priv.IsFile()) return;
try
{
sch.addIdentity(priv.FullName);
}
catch (JSchException)
{
// Instead, pretend the key doesn't exist.
}
}
示例4: getJSch
/// <summary>
/// Obtain the JSch used to create new sessions.
/// </summary>
/// <param name="hc">host configuration</param>
/// <returns>the JSch instance to use.</returns>
protected JSch getJSch(OpenSshConfig.Host hc)
{
if (hc == null)
throw new System.ArgumentNullException("hc");
JSch def = getDefaultJSch();
FileInfo identityFile = hc.getIdentityFile();
if (identityFile == null)
return def;
string identityKey = identityFile.FullName;
JSch jsch;
if(!_byIdentityFile.TryGetValue(identityKey, out jsch))
{
jsch = new JSch();
jsch.setHostKeyRepository(def.getHostKeyRepository());
jsch.addIdentity(identityKey);
_byIdentityFile.Add(identityKey, jsch);
}
return jsch;
}
示例5: SSHConnect
internal bool SSHConnect()
{
try
{
channels_ = new Dictionary<int, ChannelSftp>();
jsch_ = new JSch();
Hashtable config = new Hashtable();
config["StrictHostKeyChecking"] = "no";
if (identity_ != null)
jsch_.addIdentity(identity_, passphrase_);
session_ = jsch_.getSession(user_, host_, port_);
session_.setConfig(config);
session_.setUserInfo(new DokanUserInfo(password_, passphrase_));
session_.setPassword(password_);
session_.connect();
return true;
}
catch (Exception e)
{
Debug(e.ToString());
return false;
}
}
示例6: loadIdentity
private static void loadIdentity(JSch sch, FileInfo priv)
{
if (!File.Exists(priv.ToString())) return;
try
{
sch.addIdentity(Path.GetFullPath(priv.ToString()));
}
catch (JSchException)
{
}
}
示例7: getJSch
protected JSch getJSch(OpenSshConfig.Host hc)
{
JSch def = getDefaultJSch();
FileInfo identityFile = hc.getIdentityFile();
if (identityFile == null)
return def;
string identityKey = Path.GetFullPath(identityFile.ToString());
JSch jsch = byIdentityFile[identityKey];
if (jsch == null)
{
jsch = new JSch();
jsch.setHostKeyRepository(def.getHostKeyRepository());
jsch.addIdentity(identityKey);
byIdentityFile.Add(identityKey, jsch);
}
return jsch;
}
示例8: GetCurFileList
public void GetCurFileList()
{
InitVAHInfo();
try
{
JSch jsch = new JSch();
Session ssn = jsch.getSession(_usr, _hip, _hp);
System.Collections.Hashtable hashConfig = new Hashtable();
hashConfig.Add("StrictHostKeyChecking", "No");
ssn.setConfig(hashConfig);
jsch.addIdentity(_ppk);
ssn.connect();
if (ssn.isConnected())
{
Console.WriteLine("Log Successfully.");
Channel chnnl = ssn.openChannel("sftp");
chnnl.connect();
if (chnnl.isConnected())
{
Console.WriteLine("sftp channel opened.");
if (!string.IsNullOrEmpty(Resources.InitListDirectory))
{
_initdir = (string)Resources.InitListDirectory.Replace(":", "").Replace("\\", "/");
if (!_initdir.Contains("cygdrive"))
_initdir = "/cygdrive/" + _initdir;
ChannelSftp sftp = (ChannelSftp)chnnl;
try
{
Console.WriteLine("List {0}:", Resources.InitListDirectory);
ArrayList lst = sftp.ls(_initdir);
foreach (ChannelSftp.LsEntry fstat in lst)
{
Console.WriteLine("{0} {1:D5} {2:D5} {3} {4}",
fstat.getAttrs().getPermissionsString(),
fstat.getAttrs().getUId(),
fstat.getAttrs().getGId(),
Util.Time_T2DateTime((uint)fstat.getAttrs().getMTime()).ToString("yyyy-MM-dd HH:mm:ss"),
fstat.getFilename());
}
}
catch (Tamir.SharpSsh.jsch.SftpException sftpex)
{
Console.WriteLine(sftpex.message);
}
catch (Exception anyex)
{
Console.WriteLine(anyex.Message);
}
}
chnnl.disconnect();
}
ssn.disconnect();
}
else
Console.WriteLine("Log failed.");
}
catch (Tamir.SharpSsh.jsch.JSchException jschex)
{
Console.WriteLine(jschex.Message);
}
catch (Exception anyex)
{
Console.WriteLine(anyex.Message);
}
Console.WriteLine("Bye");
}