addIdentity() public method

public addIdentity ( String foo ) : void
foo String
return void
コード例 #1
0
ファイル: TestShell.cs プロジェクト: rogerluo/testcsharp
 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
0
ファイル: UserAuthPubKey.cs プロジェクト: stux2000/dokan
		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 username@hostname",
					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
0
 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
0
        /// <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
0
ファイル: DokanOperations.cs プロジェクト: stux2000/dokan
        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
0
        private static void loadIdentity(JSch sch, FileInfo priv)
        {
            if (!File.Exists(priv.ToString())) return;
            try
            {
                sch.addIdentity(Path.GetFullPath(priv.ToString()));
            }
            catch (JSchException)
            {

            }
        }
コード例 #7
0
        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
0
ファイル: TestShell.cs プロジェクト: rogerluo/testcsharp
        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");
        }