當前位置: 首頁>>代碼示例>>C#>>正文


C# jsch.Session類代碼示例

本文整理匯總了C#中Tamir.SharpSsh.jsch.Session的典型用法代碼示例。如果您正苦於以下問題:C# Session類的具體用法?C# Session怎麽用?C# Session使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Session類屬於Tamir.SharpSsh.jsch命名空間,在下文中一共展示了Session類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
     }
 }
開發者ID:rogerluo,項目名稱:testcsharp,代碼行數:30,代碼來源:TestShell.cs

示例2: getPort

		internal static PortWatcher getPort(Session session, String address, int lport)
		{
			IPAddress addr;
			try
			{
				addr = Dns.GetHostEntry(address).AddressList[0];
			}
			catch(Exception)
			{
				throw new JSchException("PortForwardingL: invalid address "+address+" specified.");
			}
			lock(pool)
			{
				for(int i=0; i<pool.Count; i++)
				{
					PortWatcher p=(PortWatcher)(pool[i]);
					if(p.session==session && p.lport==lport)
					{

						if (
							IPAddress.IsLoopback(p.boundaddress) ||
							p.boundaddress == addr
						)
						{
							return p;
						}
					}
				}
				return null;
			}
		}
開發者ID:soywiz,項目名稱:csharputils,代碼行數:31,代碼來源:PortWatcher.cs

示例3: getFakedCookie

		internal static byte[] getFakedCookie(Session session)
		{
			lock(faked_cookie_hex_pool)
			{
				byte[] foo=(byte[])faked_cookie_hex_pool[session];
				if(foo==null)
				{
					Random random=Session.random;
					foo=new byte[16];
					lock(random)
					{
						random.fill(foo, 0, 16);
					}
					/*
					System.out.print("faked_cookie: ");
					for(int i=0; i<foo.length; i++){
						System.out.print(Integer.toHexString(foo[i]&0xff)+":");
					}
					System.out.println("");
					*/
					faked_cookie_pool.Add(session, foo);
					byte[] bar=new byte[32];
					for(int i=0; i<16; i++)
					{
						bar[2*i]=table[(foo[i]>>4)&0xf];
						bar[2*i+1]=table[(foo[i])&0xf];
					}
					faked_cookie_hex_pool.Add(session, bar);
					foo=bar;
				}
				return foo;
			}
		}
開發者ID:MatanDavidCohen,項目名稱:StockAnalyzerWin,代碼行數:33,代碼來源:ChannelX11.cs

示例4: 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

示例5: request

		public void request(Session session, Channel channel)
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);

			bool reply=waitForReply();
			if(reply)
			{
				channel.reply=-1;
			}

			packet.reset();
			buf.putByte((byte)Session.SSH_MSG_CHANNEL_REQUEST);
			buf.putInt(channel.getRecipient());
			buf.putString(Util.getBytes("subsystem"));
			buf.putByte((byte)(waitForReply() ? 1 : 0));
			buf.putString(Util.getBytes("sftp"));
			session.write(packet);

			if(reply)
			{
				while(channel.reply==-1)
				{
					try{System.Threading.Thread.Sleep(10);}
					catch//(Exception ee)
					{
					}
				}
				if(channel.reply==0)
				{
					throw new JSchException("failed to send sftp request");
				}
			}
		}
開發者ID:stux2000,項目名稱:dokan,代碼行數:34,代碼來源:RequestSftp.cs

示例6: getPort

		internal static PortWatcher getPort(Session session, String address, int lport)
		{
			InetAddress addr;
			try
			{
				addr=InetAddress.getByName(address);
			}
			catch(Exception uhe)
			{
				throw new JSchException("PortForwardingL: invalid address "+address+" specified.");
			}
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					PortWatcher p=(PortWatcher)(pool.elementAt(i));
					if(p.session==session && p.lport==lport)
					{
						if(p.boundaddress.isAnyLocalAddress() ||
							p.boundaddress.equals(addr))
							return p;
					}
				}
				return null;
			}
		}
開發者ID:MatanDavidCohen,項目名稱:StockAnalyzerWin,代碼行數:26,代碼來源:PortWatcher.cs

示例7: 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

示例8: configure

 protected override void configure(OpenSshConfig.Host hc, Session session)
 {
     if (!hc.isBatchMode())
     {
     #warning need something to replace jgit gui infrastructure as gitsharp is library only
         throw new NotImplementedException("GUI Configuration is not available");
     }
 }
開發者ID:georgeck,項目名稱:GitSharp,代碼行數:8,代碼來源:DefaultSshSessionFactory.cs

示例9: releaseSession

        public void releaseSession(Session session)
        {
            if (session == null)
                throw new System.ArgumentNullException ("session");

            if (session.isConnected())
                session.disconnect();
        }
開發者ID:stschake,項目名稱:GitSharp,代碼行數:8,代碼來源:SshSessionFactory.cs

示例10: 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

示例11: init

		public override void init(Session session,
			byte[] V_S, byte[] V_C, byte[] I_S, byte[] I_C) 
		{
			this.session=session;
			this.V_S=V_S;      
			this.V_C=V_C;      
			this.I_S=I_S;      
			this.I_C=I_C;      

			//    sha=new SHA1();
			//    sha.init();
			try
			{
				Type t=Type.GetType(session.getConfig("sha-1"));
				sha=(HASH)(Activator.CreateInstance(t));
				sha.init();
			}
			catch(Exception ee)
			{
				Console.WriteLine(ee);
			}

			buf=new Buffer();
			packet=new Packet(buf);

			try
			{
				Type t=Type.GetType(session.getConfig("dh"));
				dh=(DH)(Activator.CreateInstance(t));
				dh.init();
			}
			catch(Exception ee)
			{
				throw ee;
			}

			dh.setP(p);
			dh.setG(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)

			e=dh.getE();

			packet.reset();
			buf.putByte((byte)SSH_MSG_KEXDH_INIT);
			buf.putMPInt(e);
			session.write(packet);

			state=SSH_MSG_KEXDH_REPLY;
		}
開發者ID:stux2000,項目名稱:dokan,代碼行數:53,代碼來源:DHG1.cs

示例12: getChannel

		internal static Channel getChannel(int id, Session session)
		{
			lock(pool)
			{
				for(int i=0; i<pool.Count; i++)
				{
					Channel c=(Channel)(pool[i]);
					if(c.id==id && c.session==session) return c;
				}
			}
			return null;
		}
開發者ID:soywiz,項目名稱:csharputils,代碼行數:12,代碼來源:Channel.cs

示例13: getChannel

		internal static Channel getChannel(int id, Session session)
		{
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					Channel c=(Channel)(pool.elementAt(i));
					if(c.id==id && c.session==session) return c;
				}
			}
			return null;
		}
開發者ID:MatanDavidCohen,項目名稱:StockAnalyzerWin,代碼行數:12,代碼來源:Channel.cs

示例14: request

		public void request(Session session, Channel channel)
		{
			Buffer buf=new Buffer();
			Packet packet=new Packet(buf);

			packet.reset();
			buf.putByte((byte) Session.SSH_MSG_CHANNEL_REQUEST);
			buf.putInt(channel.getRecipient());
			buf.putString( Util.getBytes("signal"));
			buf.putByte((byte)(waitForReply() ? 1 : 0));
			buf.putString(Util.getBytes(signal));
			session.write(packet);
		}
開發者ID:MatanDavidCohen,項目名稱:StockAnalyzerWin,代碼行數:13,代碼來源:RequestSignal.cs

示例15: _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


注:本文中的Tamir.SharpSsh.jsch.Session類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。