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


C# SshNet.ConnectionInfo类代码示例

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


ConnectionInfo类属于Renci.SshNet命名空间,在下文中一共展示了ConnectionInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SftpUploader

 public SftpUploader(AppConfig conf)
 {
     this.config = conf;
     if (config.sftpEnabled)
     {
         AuthenticationMethod[] auths = new AuthenticationMethod[1];
         if (String.IsNullOrWhiteSpace(config.sftpPrivateKeyPath))
         {
             auths[0] = new PasswordAuthenticationMethod(config.sftpUsername, Utils.GetBytes(config.sftpPassword));
         }
         else
         {
             try
             {
                 PrivateKeyFile pkf = null;
                 if (string.IsNullOrEmpty(config.sftpPassword))
                 {
                     pkf = new PrivateKeyFile(config.sftpPrivateKeyPath);
                 }
                 else
                 {
                     pkf = new PrivateKeyFile(config.sftpPrivateKeyPath, config.sftpPassword);
                 }
                 auths[0] = new PrivateKeyAuthenticationMethod(config.sftpUsername, pkf);
             }
             catch (IOException)
             {
                 Log.Error("Unable to read private key file: " + config.sftpPrivateKeyPath);
                 return;
             }
         }
         connInfo = new ConnectionInfo(config.sftpRemoteServer, config.sftpUsername, auths);
     }
 }
开发者ID:Elusive138,项目名称:YASDown,代码行数:34,代码来源:SftpUploader.cs

示例2: ExecuteCcm

        public override ProcessOutput ExecuteCcm(string args, int timeout = 90000, bool throwOnProcessError = true)
        {
            var executable = GetExecutable(ref args);
            Trace.TraceInformation(executable + " " + args);

            var output = new ProcessOutput();
            if (_sshClient == null)
            {
                Trace.TraceInformation("Connecting ssh client...");
                var kauth = new KeyboardInteractiveAuthenticationMethod(_user);
                var pauth = new PasswordAuthenticationMethod(_user, _password);

                var connectionInfo = new ConnectionInfo(_ip, _port, _user, kauth, pauth);

                kauth.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
                {
                    foreach (var prompt in e.Prompts)
                    {
                        if (prompt.Request.ToLowerInvariant().StartsWith("password"))
                        {
                            prompt.Response = _password;
                        }
                    }
                };

                if (!string.IsNullOrEmpty(_privateKeyFilePath))
                {
                    var privateKeyAuth = new PrivateKeyAuthenticationMethod(_user, new PrivateKeyFile[]
                    {
                        new PrivateKeyFile(_privateKeyFilePath)
                    });
                    connectionInfo = new ConnectionInfo(_ip, _port, _user, privateKeyAuth);
                }

                _sshClient = new SshClient(connectionInfo);
            }
            if (!_sshClient.IsConnected)
                _sshClient.Connect();

            var result = _sshClient.RunCommand(string.Format(@"{0} {1}", executable, args));
            output.ExitCode = result.ExitStatus;
            if (result.Error != null)
            {
                output.OutputText.Append(result.Error);
            }
            else
            {
                output.OutputText.Append(result.Result);
            }

            if (throwOnProcessError)
            {
                ValidateOutput(output);
            }
            return output;
        }
开发者ID:datastax,项目名称:csharp-driver-dse,代码行数:56,代码来源:RemoteCcmProcessExecuter.cs

示例3: CheckConnection

        public static async Task<ConnectionReturn> CheckConnection(string teamNumberS, TimeSpan timeout)
        {
            int teamNumber;
            int.TryParse(teamNumberS, out teamNumber);


            if (teamNumber < 0)
            {
                teamNumber = 0;
            }
            string roboRioMDNS = string.Format(RoboRioMdnsFormatString, teamNumber);
            string roboRIOIP = string.Format(RoboRioIpFormatString, teamNumber / 100, teamNumber % 100);

            if (await GetWorkingConnectionInfo(roboRioMDNS, timeout))
            {
                return new ConnectionReturn(ConnectionType.MDNS, roboRioMDNS, true);
            }
            else if (await GetWorkingConnectionInfo(RoboRioUSBIp, timeout))
            {
                return new ConnectionReturn(ConnectionType.USB, RoboRioUSBIp, true);
            }
            else if (await GetWorkingConnectionInfo(roboRIOIP, timeout))
            {
                return new ConnectionReturn(ConnectionType.IP, roboRIOIP, true);
            }
            s_lvUserConnectionInfo = null;
            s_adminConnectionInfo = null;
            return null;
        }
开发者ID:RickHendrickson,项目名称:FRC-Extension,代码行数:29,代码来源:RoboRIOConnection.cs

示例4: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            string host = textBoxServer.Text.Trim();
            string userName = textBoxUserName.Text.Trim();
            string psw = textBoxPassword.Text.Trim();
            string url = textBoxCoomand.Text.Trim();
            string location = @" -P  " + textBoxLocation.Text.Trim();
            string finalCommand = @"wget -bqc '" + url + "' " + location + " ";
            ConnectionInfo conInfo = new ConnectionInfo(host, 22, userName, new AuthenticationMethod[]{
                new PasswordAuthenticationMethod(userName,psw)
            });
            SshClient client = new SshClient(conInfo);
            try
            {
                client.Connect();
                var outptu = client.RunCommand(finalCommand);
            }
            catch (Exception ex)
            {
                textBoxDisplay.Text = ex.Message;
                throw;
            }

            client.Disconnect();
            client.Dispose();
            SetLastValues(host, userName, psw, textBoxLocation.Text.Trim());
        }
开发者ID:amolmore,项目名称:remotewget,代码行数:27,代码来源:RemoteWget.cs

示例5: BaseClient

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseClient"/> class.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
        /// <param name="serviceFactory">The factory to use for creating new services.</param>
        /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="serviceFactory"/> is null.</exception>
        /// <remarks>
        /// If <paramref name="ownsConnectionInfo"/> is <c>true</c>, then the
        /// connection info will be disposed when this instance is disposed.
        /// </remarks>
        internal BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, IServiceFactory serviceFactory)
        {
            if (connectionInfo == null)
                throw new ArgumentNullException("connectionInfo");
            if (serviceFactory == null)
                throw new ArgumentNullException("serviceFactory");

            ConnectionInfo = connectionInfo;
            _ownsConnectionInfo = ownsConnectionInfo;
            _serviceFactory = serviceFactory;
            _keepAliveInterval = SshNet.Session.InfiniteTimeSpan;
        }
开发者ID:npcook,项目名称:terminal,代码行数:24,代码来源:BaseClient.cs

示例6: SftpForm

 public SftpForm(ConnectionInfo connectionInfo)
 {
     InitializeComponent();
       this.connectionInfo = connectionInfo;
       this.sftpClient = new SftpClient(this.connectionInfo);
       this.sftpClient.Connect();
       refresh();
 }
开发者ID:KenjiOhtsuka,项目名称:SSHViewer,代码行数:8,代码来源:SftpForm.cs

示例7: BaseClient

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseClient"/> class.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is null.</exception>
        public BaseClient(ConnectionInfo connectionInfo)
        {
            if (connectionInfo == null)
                throw new ArgumentNullException("connectionInfo");

            this.ConnectionInfo = connectionInfo;
            this.Session = new Session(connectionInfo);
        }
开发者ID:InoMurko,项目名称:win-sshfs,代码行数:13,代码来源:BaseClient.cs

示例8: SshExpect

 ConnectionInfo connInfo;//строка подключения
 public SshExpect(ConnectionData host)
     : base(host)
 {
     connInfo = new ConnectionInfo(host.address, host.port, host.username, new AuthenticationMethod[]{
         new PasswordAuthenticationMethod(host.username, host.password)
         }
     );
 }
开发者ID:DaurenAmanbayev,项目名称:RemoteWork,代码行数:9,代码来源:SshExpect.cs

示例9: Ssh

 public Ssh(string host, int port, string user, string pass)
 {
     _con = new ConnectionInfo(host,port,user,
         new AuthenticationMethod[]
         {
             new PasswordAuthenticationMethod(user,pass)
         });
 }
开发者ID:akritikos,项目名称:kritikos.libs,代码行数:8,代码来源:SSHClient.cs

示例10: BaseClient

        /// <summary>
        /// Initializes a new instance of the <see cref="BaseClient"/> class.
        /// </summary>
        /// <param name="connectionInfo">The connection info.</param>
        /// <param name="ownsConnectionInfo">Specified whether this instance owns the connection info.</param>
        /// <exception cref="ArgumentNullException"><paramref name="connectionInfo"/> is null.</exception>
        /// <remarks>
        /// If <paramref name="ownsConnectionInfo"/> is <c>true</c>, then the
        /// connection info will be disposed when this instance is disposed.
        /// </remarks>
        protected BaseClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo)
        {
            if (connectionInfo == null)
                throw new ArgumentNullException("connectionInfo");

            ConnectionInfo = connectionInfo;
            _ownsConnectionInfo = ownsConnectionInfo;
            _keepAliveInterval = Infinite;
        }
开发者ID:Youkyungjin,项目名称:Crawler,代码行数:19,代码来源:BaseClient.cs

示例11: UploadFile

        public void UploadFile(string fullSourcePath, string fileName)
        {
            var host = ConfigurationManager.AppSettings["Host"];
            var user = ConfigurationManager.AppSettings["User"];
            var port = ConfigurationManager.AppSettings["Port"];
            var pass = ConfigurationManager.AppSettings["Password"];
            var path = ConfigurationManager.AppSettings["Path"];
            var key = ConfigurationManager.AppSettings["PrivateKey"];

            int p = 22;
            if (!string.IsNullOrEmpty(port))
                p = int.Parse(port);

            Log.Info("Uploading '{0}' to {1}@{2}:{3}", fileName, user, host, p);

            AuthenticationMethod auth;
            if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(user)) {
                Log.Info("Using public key authentication with key {0}", key);
                auth = new PrivateKeyAuthenticationMethod(user ,new PrivateKeyFile[]{ new PrivateKeyFile(key) });
            } else if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(pass)){
                Log.Info("Using password authentication");
                auth = new PasswordAuthenticationMethod(user,pass);
            } else {
                throw new Exception("Please ensure that username, and either PrivateKey or Password setting are defined in the configuration file.");
            }

            ConnectionInfo ConnNfo = new ConnectionInfo(host, p, user, new AuthenticationMethod[]{ auth } );

            string targetPath = fileName;
            if (!String.IsNullOrEmpty(path)) {
                // If the Path config setting specifies the file name,
                // then ignore the local file name and always upload to the same target
                if (!String.IsNullOrWhiteSpace(Path.GetFileName(path))) {
                    targetPath = path;
                } else {
                    targetPath = Path.Combine(path, targetPath);
                    // To avoid path guessing by .NET, we first combine the path, then force
                    // potential backslashes with linux slashes.
                    // This will obviously kill any space escaping in the path, so we need to bring those back
                    bool hadSpaceEscapes = targetPath.Contains("\\ ");
                    targetPath = targetPath.Replace('\\', '/');
                    if (hadSpaceEscapes)
                        targetPath = targetPath.Replace("/ ", "\\ ");
                }
            }

            using (var scp = new ScpClient(ConnNfo)) {
                scp.Connect();

                Log.Info("Connection opened, uploading file.");
                scp.Upload(new FileInfo(fullSourcePath), targetPath);
                Log.Info("File uploaded, closing connection.");
                scp.Disconnect();
            }
        }
开发者ID:wa-research,项目名称:ServiceManager,代码行数:55,代码来源:QueueWatcher.cs

示例12: addSftpTab

 private void addSftpTab(ConnectionInfo connectionInfo)
 {
     TabPage t = new TabPage(connectionInfo.Host);
     SftpForm f = new SftpForm(connectionInfo);
     f.Location = new Point(10, 10);
     f.TopLevel = false;
     f.Dock = DockStyle.Fill;
     f.Visible = true;
     t.Controls.Add(f);
     sftpTabControl.TabPages.Add(t);
 }
开发者ID:KenjiOhtsuka,项目名称:SSHViewer,代码行数:11,代码来源:MainForm.cs

示例13: SftpFilesystem

 public SftpFilesystem(ConnectionInfo connectionInfo, string rootpath,string label=null, bool useOfflineAttribute = false,
              bool debugMode = false, int attributeCacheTimeout = 5, int directoryCacheTimeout = 60)
     : base(connectionInfo)
 {
     _rootpath = rootpath;
     _directoryCacheTimeout = directoryCacheTimeout;
     _attributeCacheTimeout = attributeCacheTimeout;
     _useOfflineAttribute = useOfflineAttribute;
     _debugMode = debugMode;
     _volumeLabel = label??String.Format("{0} on '{1}'", ConnectionInfo.Username, ConnectionInfo.Host);
 }
开发者ID:leocheang422,项目名称:win-sshfs,代码行数:11,代码来源:SftpFilesystem.cs

示例14: Connect

        public void Connect()
        {
            PluginConfigurationEntity configuration;
            using (var gateway = GlobalConfigurationGatewayFactory())
            {
                configuration = gateway.GetGlobalConfiguration();
            }

            var keyStream = new MemoryStream(Encoding.UTF8.GetBytes(configuration.PrivateKey));
            var connectionInfo = new ConnectionInfo(configuration.Host, configuration.Port, configuration.User,
                new PrivateKeyAuthenticationMethod(configuration.User, new PrivateKeyFile(keyStream)));
            _sshClient = new Renci.SshNet.SshClient(connectionInfo);
            _sshClient.Connect();
        }
开发者ID:justinconnell,项目名称:remi,代码行数:14,代码来源:SshClient.cs

示例15: Main

        static void Main(string[] args)
        {
            string servers = ConfigurationManager.AppSettings["servers"];
            string username = ConfigurationManager.AppSettings["username"];
            string password = ConfigurationManager.AppSettings["password"];
            foreach (string server in servers.Split(','))
            {
                ConnectionInfo ConnNfo = new ConnectionInfo(server, 22, username,
                    new AuthenticationMethod[]{
                        // Pasword based Authentication
                        new PasswordAuthenticationMethod(username,password)
                    }
                    );

                string[] items = { "active_pwr", "energy_sum", "v_rms", "pf","enabled" };

                using (var sshclient = new SshClient(ConnNfo))
                {
                    Console.WriteLine("Connecting to {0}", server);
                    sshclient.Connect();
                    // quick way to use ist, but not best practice - SshCommand is not Disposed, ExitStatus not checked...
                    foreach (string itemName in items)
                    {
                        for (int port = 1; port < 7; port++)
                        {
                            string outputFileName = string.Format("{0}-{1}-{2}.txt", server, itemName, port);
                            Console.WriteLine(string.Format("{0}{1}", itemName, port));
                            string result = sshclient.CreateCommand(string.Format("cat /proc/power/{0}{1}", itemName, port)).Execute();
                            if (!File.Exists(outputFileName))
                            {
                                using (var writer = File.CreateText(outputFileName))
                                {
                                    writer.WriteLine(string.Format("{0}, {1}", DateTime.Now.Ticks, result));
                                }
                            }
                            else
                            {
                                using (var writer = File.AppendText(outputFileName))
                                {
                                    writer.WriteLine(string.Format("{0}, {1}", DateTime.Now.Ticks, result));
                                }
                            }
                            Console.WriteLine(result);
                        }
                    }
                    sshclient.Disconnect();
                }
            }
        }
开发者ID:tiernano,项目名称:ubntmpowerreader,代码行数:49,代码来源:Program.cs


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