本文整理汇总了C#中Tamir.SharpSsh.jsch.JSch类的典型用法代码示例。如果您正苦于以下问题:C# JSch类的具体用法?C# JSch怎么用?C# JSch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSch类属于Tamir.SharpSsh.jsch命名空间,在下文中一共展示了JSch类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RunExample
public static void RunExample(String[] arg)
{
try
{
//Create a new JSch instance
JSch jsch=new JSch();
//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);
//Add AES128 as default cipher in the session config store
System.Collections.Hashtable config=new System.Collections.Hashtable();
config.Add("cipher.s2c", "aes128-cbc,3des-cbc");
config.Add("cipher.c2s", "aes128-cbc,3des-cbc");
session.setConfig(config);
//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();
Console.WriteLine("-- Shell channel is connected using the {0} cipher",
session.getCipher());
//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.Message);
}
}
开发者ID:stux2000,项目名称:dokan,代码行数:60,代码来源:AES.cs
示例2: Run
public static void Run()
{
JSch jsch=new JSch();
Session session=jsch.getSession("root", "rhmanage", 22);
session.setPassword( "cisco" );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("ifconfig");
StreamReader sr = new StreamReader( channel.getInputStream() );
channel.connect();
string line;
while( (line=sr.ReadLine()) != null )
{
Console.WriteLine( line );
}
channel.disconnect();
session.disconnect();
}
开发者ID:MatanDavidCohen,项目名称:StockAnalyzerWin,代码行数:29,代码来源:ExecTest.cs
示例3: SshBase
/// <summary>
/// Constructs a new SSH instance
/// </summary>
/// <param name="sftpHost">The remote SSH host</param>
/// <param name="user">The login username</param>
/// <param name="password">The login password</param>
public SshBase(string sftpHost, string user, string password)
{
this.m_host = sftpHost;
this.m_user = user;
this.Password = password;
m_jsch = new JSch();
}
开发者ID:stux2000,项目名称:dokan,代码行数:13,代码来源:SshBase.cs
示例4: 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();
}
}
开发者ID:Chaplain,项目名称:WowPacketParser,代码行数:26,代码来源:SSHTunnel.cs
示例5: 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);
}
}
开发者ID:rogerluo,项目名称:testcsharp,代码行数:30,代码来源:TestShell.cs
示例6: SshHelper
public SshHelper(string host, string username, string password)
{
this.host = host;
JSch jsch=new JSch();
Session session=jsch.getSession(username, host, 22);
session.setPassword( password );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
channel=(ChannelShell)session.openChannel("shell");
writer_po = new PipedOutputStream();
PipedInputStream writer_pi = new PipedInputStream( writer_po );
PipedInputStream reader_pi = new PipedInputStream();
PipedOutputStream reader_po = new PipedOutputStream( reader_pi );
reader = new StreamReader (reader_pi,Encoding.UTF8);
channel.setInputStream( writer_pi );
channel.setOutputStream( reader_po );
channel.connect();
channel.setPtySize(132, 132, 1024, 768);
}
开发者ID:yash0924,项目名称:csharputils,代码行数:28,代码来源:SshHelper.cs
示例7: SshHelper
public SshHelper(string Host, string UserName, string Password)
{
host = Host;
var jsch = new JSch();
session = jsch.getSession(UserName, host, 22);
session.setPassword(Password);
var config = new Hashtable { { "StrictHostKeyChecking", "no" } };
session.setConfig(config);
session.connect();
channel = (ChannelShell)session.openChannel("shell");
writer_po = new PipedOutputStream();
var writer_pi = new PipedInputStream(writer_po);
var reader_pi = new PipedInputStream();
var reader_po = new PipedOutputStream(reader_pi);
reader = new StreamReader(reader_pi, Encoding.UTF8);
channel.setInputStream(writer_pi);
channel.setOutputStream(reader_po);
channel.connect();
channel.setPtySize(132, 132, 1024, 768);
}
开发者ID:gamchantoi,项目名称:astra-contact-manager,代码行数:27,代码来源:SshHelper.cs
示例8: getFingerPrint
public String getFingerPrint(JSch jsch){
HASH hash=null;
try{
hash=(HASH)Activator.CreateInstance(Type.GetType(jsch.getConfig("md5")));
}
catch(Exception e){ Console.Error.WriteLine("getFingerPrint: "+e); }
return Util.getFingerPrint(hash, key);
}
开发者ID:stux2000,项目名称:dokan,代码行数:8,代码来源:HostKey.cs
示例9: 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);
}
}
开发者ID:stux2000,项目名称:dokan,代码行数:58,代码来源:UserAuthPubKey.cs
示例10: RunExample
public static void RunExample(params string[] arg)
{
if(arg.Length<3)
{
Console.Error.WriteLine(
"usage: java KeyGen rsa output_keyfile comment\n"+
" java KeyGen dsa output_keyfile comment");
return;
}
try
{
//Get sig type ('rsa' or 'dsa')
String _type=arg[0];
int type=0;
if(_type.Equals("rsa")){type=KeyPair.RSA;}
else if(_type.Equals("dsa")){type=KeyPair.DSA;}
else
{
Console.Error.WriteLine(
"usage: java KeyGen rsa output_keyfile comment\n"+
" java KeyGen dsa output_keyfile comment");
return;
}
//Output file name
String filename=arg[1];
//Signature comment
String comment=arg[2];
//Create a new JSch instance
JSch jsch=new JSch();
//Prompt the user for a passphrase for the private key file
String passphrase=InputForm.GetUserInput("Enter passphrase (empty for no passphrase)", true);
//Generate the new key pair
KeyPair kpair=KeyPair.genKeyPair(jsch, type);
//Set a passphrase
kpair.setPassphrase(passphrase);
//Write the private key to "filename"
kpair.writePrivateKey(filename);
//Write the public key to "filename.pub"
kpair.writePublicKey(filename+".pub", comment);
//Print the key fingerprint
Console.WriteLine("Finger print: "+kpair.getFingerPrint());
//Free resources
kpair.dispose();
}
catch(Exception e)
{
Console.WriteLine(e);
}
return;
}
开发者ID:TonyZhu2015,项目名称:sharpssh,代码行数:55,代码来源:KeyGen.cs
示例11: genKeyPair
public static KeyPair genKeyPair(JSch jsch, int type, int key_size)
{
KeyPair kpair=null;
if(type==DSA){ kpair=new KeyPairDSA(jsch); }
else if(type==RSA){ kpair=new KeyPairRSA(jsch); }
if(kpair!=null)
{
kpair.generate(key_size);
}
return kpair;
}
开发者ID:stux2000,项目名称:dokan,代码行数:11,代码来源:KeyPair.cs
示例12: SftpHelper
/// <summary>
/// 构造方法
/// </summary>
/// <param name="host"></param>
/// <param name="user"></param>
/// <param name="pwd"></param>
public SftpHelper(string host, string user, string pwd)
{
string[] arr = host.Split(':');
string ip = arr[0];
int port = 22;
if (arr.Length > 1) port = Int32.Parse(arr[1]);
JSch jsch = new JSch();
m_session = jsch.getSession(user, ip, port);
MyUserInfo ui = new MyUserInfo();
ui.setPassword(pwd);
m_session.setUserInfo(ui);
}
开发者ID:rexyanglucky,项目名称:uba,代码行数:18,代码来源:SftpHelper.cs
示例13: RunExample
public static void RunExample(String[] arg)
{
if(arg.Length<3)
{
Console.Error.WriteLine(
"usage: java KeyGen rsa output_keyfile comment\n"+
" java KeyGen dsa output_keyfile comment");
Environment.Exit(-1);
}
String _type=arg[0];
int type=0;
if(_type.Equals("rsa")){type=KeyPair.RSA;}
else if(_type.Equals("dsa")){type=KeyPair.DSA;}
else
{
Console.Error.WriteLine(
"usage: java KeyGen rsa output_keyfile comment\n"+
" java KeyGen dsa output_keyfile comment");
Environment.Exit(-1);
}
String filename=arg[1];
String comment=arg[2];
JSch jsch=new JSch();
String passphrase="";
InputForm passphraseField=new InputForm();
passphraseField.PasswordField = true;
Object[] ob={passphraseField};
passphraseField.Text="Enter passphrase (empty for no passphrase)";
bool result=passphraseField.PromptForInput();
if(result)
{
passphrase=passphraseField.getText();
}
try
{
KeyPair kpair=KeyPair.genKeyPair(jsch, type);
kpair.setPassphrase(passphrase);
kpair.writePrivateKey(filename);
kpair.writePublicKey(filename+".pub", comment);
Console.WriteLine("Finger print: "+kpair.getFingerPrint());
kpair.dispose();
}
catch(Exception e)
{
Console.WriteLine(e);
}
Environment.Exit(0);
}
开发者ID:mzkabbani,项目名称:cSharpProjects,代码行数:52,代码来源:KeyGen.cs
示例14: RunExample
public static void RunExample(String[] arg)
{
int port;
try
{
//Create a new JSch instance
JSch jsch=new JSch();
//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);
session.connect();
//Get from user the remote host and remote host port
String foo = InputForm.GetUserInput("Enter host and port", "host:port");
host=foo.Substring(0, foo.IndexOf(':'));
port=int.Parse(foo.Substring(foo.IndexOf(':')+1));
Console.WriteLine("System.{in,out} will be forwarded to "+
host+":"+port+".");
Channel channel=session.openChannel("direct-tcpip");
((ChannelDirectTCPIP)channel).setInputStream(Console.OpenStandardInput());
((ChannelDirectTCPIP)channel).setOutputStream(Console.OpenStandardOutput());
((ChannelDirectTCPIP)channel).setHost(host);
((ChannelDirectTCPIP)channel).setPort(port);
channel.connect();
while(!channel.isClosed())
{
System.Threading.Thread.Sleep(500);
}
channel.disconnect();
session.disconnect();
}
catch(Exception e)
{
Console.WriteLine(e);
}
}
开发者ID:stux2000,项目名称:dokan,代码行数:51,代码来源:StreamForwarding.cs
示例15: RunExample
public static void RunExample(String[] arg)
{
//Get the private key filename from the user
Console.WriteLine("Please choose your private key file...");
String pkey = InputForm.GetFileFromUser("Choose your privatekey(ex. ~/.ssh/id_dsa)");
Console.WriteLine("You chose "+pkey+".");
//Create a new JSch instance
JSch jsch=new JSch();
try
{
//Load the key pair
KeyPair kpair=KeyPair.load(jsch, pkey);
//Print the key file encryption status
Console.WriteLine(pkey+" has "+(kpair.isEncrypted()?"been ":"not been ")+"encrypted");
String passphrase = "";
while(kpair.isEncrypted())
{
passphrase = InputForm.GetUserInput("Enter passphrase for "+pkey, true);
if(!kpair.decrypt(passphrase))
{
Console.WriteLine("failed to decrypt "+pkey);
}
else
{
Console.WriteLine(pkey+" is decrypted.");
}
}
passphrase="";
passphrase=InputForm.GetUserInput("Enter new passphrase for "+pkey+
" (empty for no passphrase)", true);
//Set the new passphrase
kpair.setPassphrase(passphrase);
//write the key to file
kpair.writePrivateKey(pkey);
//free the resource
kpair.dispose();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
开发者ID:stux2000,项目名称:dokan,代码行数:50,代码来源:ChangePassphrase.cs
示例16: _Connect
protected void _Connect()
{
_jsch = new JSch();
//session.setConfig();
_session = _jsch.getSession(this.Username, this.Host, this.Port);
UserInfo ui = new DirectPasswordUserInfo(this.Password);
_session.setUserInfo(ui);
_session.connect();
_csftp = (ChannelSftp)_session.openChannel("sftp");
_csftp.connect();
//RootPath = csftp.getHome();
RootPath = "";
}
开发者ID:soywiz,项目名称:csharputils,代码行数:15,代码来源:SftpFileSystem.cs
示例17: test
public static void test()
{
JSch jsch = new JSch();
DH dh1 = null;
DH dh2 = null;
try
{
Type t=Type.GetType(jsch.getConfig("dh"));
dh1=(DH)(Activator.CreateInstance(t));
dh1.init();
dh2=(DH)(Activator.CreateInstance(t));
dh2.init();
}
catch(Exception ee)
{
Console.WriteLine(ee);
}
dh1.setP(DHG1.p);
dh1.setG(DHG1.g);
dh2.setP(DHG1.p);
dh2.setG(DHG1.g);
// The client responds with:
// byte SSH_MSG_KEXDH_INIT(30)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
byte[] e=dh1.getE();
byte[] f=dh2.getE();
Console.WriteLine("Private1 = {0}", hex(e));
Console.WriteLine();
Console.WriteLine("Private2 = {0}", hex(f));
Console.WriteLine();
dh1.setF(f);
dh2.setF(e);
byte[] k1 = dh1.getK();
byte[] k2 = dh2.getK();
Console.WriteLine("Public1 = {0}", hex(k1));
Console.WriteLine();
Console.WriteLine("Public2 = {0}", hex(k2));
Console.WriteLine();
}
开发者ID:stux2000,项目名称:dokan,代码行数:43,代码来源:Main.cs
示例18: RunExample
public static void RunExample(String[] arg)
{
//int port;
try
{
//Create a new JSch instance
JSch jsch=new JSch();
//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);
//Get from user the local port, remote host and remote host port
String foo = InputForm.GetUserInput("Enter -L port:host:hostport","port:host:hostport");
int lport=int.Parse(foo.Substring(0, foo.IndexOf(':')));
foo=foo.Substring(foo.IndexOf(':')+1);
String rhost=foo.Substring(0, foo.IndexOf(':'));
int rport=int.Parse(foo.Substring(foo.IndexOf(':')+1));
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
session.connect();
Console.WriteLine("localhost:"+lport+" -> "+rhost+":"+rport);
//Set port forwarding on the opened session
session.setPortForwardingL(lport, rhost, rport);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
开发者ID:TonyZhu2015,项目名称:sharpssh,代码行数:42,代码来源:PortForwardingL.cs
示例19: SshStream
/// <summary>
/// Constructs a new SSH stream.
/// </summary>
/// <param name="host">The hostname or IP address of the remote SSH machine</param>
/// <param name="username">The name of the user connecting to the remote machine</param>
/// <param name="password">The password of the user connecting to the remote machine</param>
public SshStream(string host, string username, string password)
{
this.m_host = host;
JSch jsch=new JSch();
m_session=jsch.getSession(username, host, 22);
m_session.setPassword( password );
Hashtable config=new Hashtable();
config.Add("StrictHostKeyChecking", "no");
m_session.setConfig(config);
m_session.connect();
m_channel=(ChannelShell)m_session.openChannel("shell");
m_in = m_channel.getInputStream();
m_out = m_channel.getOutputStream();
m_channel.connect();
m_channel.setPtySize(80, 132, 1024, 768);
Prompt = "\n";
m_escapeCharPattern = "\\[[0-9;?]*[^0-9;]";
}
开发者ID:MatanDavidCohen,项目名称:StockAnalyzerWin,代码行数:29,代码来源:SshStream.cs
示例20: RunExample
public static void RunExample(String[] arg)
{
try
{
JSch jsch=new JSch();
InputForm inForm = new InputForm();
inForm.Text = "Enter [email protected]";
inForm.textBox1.Text = Environment.UserName+"@localhost";
if (!inForm.PromptForInput())
{
Console.WriteLine("Cancelled");
return;
}
String host = inForm.textBox1.Text;
String user=host.Substring(0, host.IndexOf('@'));
host=host.Substring(host.IndexOf('@')+1);
Session session=jsch.getSession(user, host, 22);
// username and password will be given via UserInfo interface.
UserInfo ui=new MyUserInfo();
session.setUserInfo(ui);
session.connect();
Channel channel=session.openChannel("sftp");
channel.connect();
ChannelSftp c=(ChannelSftp)channel;
Stream ins=Console.OpenStandardInput();
TextWriter outs=Console.Out;
ArrayList cmds=new ArrayList();
byte[] buf=new byte[1024];
int i;
String str;
int level=0;
while(true)
{
outs.Write("sftp> ");
cmds.Clear();
i=ins.Read(buf, 0, 1024);
if(i<=0)break;
i--;
if(i>0 && buf[i-1]==0x0d)i--;
//str=Util.getString(buf, 0, i);
//Console.WriteLine("|"+str+"|");
int s=0;
for(int ii=0; ii<i; ii++)
{
if(buf[ii]==' ')
{
if(ii-s>0){ cmds.Add(Util.getString(buf, s, ii-s)); }
while(ii<i){if(buf[ii]!=' ')break; ii++;}
s=ii;
}
}
if(s<i){ cmds.Add(Util.getString(buf, s, i-s)); }
if(cmds.Count==0)continue;
String cmd=(String)cmds[0];
if(cmd.Equals("quit"))
{
c.quit();
break;
}
if(cmd.Equals("exit"))
{
c.exit();
break;
}
if(cmd.Equals("rekey"))
{
session.rekey();
continue;
}
if(cmd.Equals("compression"))
{
if(cmds.Count<2)
{
outs.WriteLine("compression level: "+level);
continue;
}
try
{
level=int.Parse((String)cmds[1]);
Hashtable config=new Hashtable();
if(level==0)
{
config.Add("compression.s2c", "none");
config.Add("compression.c2s", "none");
}
else
{
config.Add("compression.s2c", "zlib,none");
config.Add("compression.c2s", "zlib,none");
//.........这里部分代码省略.........
开发者ID:TonyZhu2015,项目名称:sharpssh,代码行数:101,代码来源:Sftp.cs
注:本文中的Tamir.SharpSsh.jsch.JSch类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论