当前位置: 首页>>代码示例>>C#>>正文


C# jsch.JSch类代码示例

本文整理汇总了C#中Tamir.SharpSsh.jsch.JSch的典型用法代码示例。如果您正苦于以下问题:C# JSch类的具体用法?C# JSch怎么用?C# JSch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSch类属于Tamir.SharpSsh.jsch命名空间,在下文中一共展示了JSch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的Tamir.SharpSsh.jsch.JSch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。