Example #1
0
        /// <summary>
        /// Dispose(bool disposing) executes in two distinct scenarios.
        /// If disposing equals true, the method has been called directly
        /// or indirectly by a user's code. Managed and unmanaged resources
        /// can be disposed.
        /// If disposing equals false, the method has been called by the
        /// runtime from inside the finalizer and you should not reference
        /// other objects. Only unmanaged resources can be disposed.
        /// </summary>
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this._disposed)
            {
                // Note disposing has been done.
                _disposed = true;

                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    if (_sshClient != null)
                    {
                        _sshClient.Dispose();
                    }

                    if (_sshConnection != null)
                    {
                        _sshConnection.Dispose();
                    }
                }

                // Call the appropriate methods to clean up
                // unmanaged resources here.
                _sshClient     = null;
                _sshConnection = null;
            }
        }
Example #2
0
        /// <summary>
        /// SSH Secure copy protocol.
        /// </summary>
        /// <param name="sshConnection">SSH connection adapter.</param>
        public SshScp(SshConnection sshConnection)
        {
            _sshConnection = sshConnection;
            _scp           = new Scp(sshConnection.Host, sshConnection.Username);

            // Get the authentication used.
            if (sshConnection.IsPrivateKeyAuthentication)
            {
                // For each private key file.
                foreach (PrivateKeyFile keyFile in sshConnection.PrivateKeyFiles)
                {
                    // If a file exists.
                    if (!String.IsNullOrEmpty(keyFile.PrivateKey) && !String.IsNullOrEmpty(keyFile.PrivateKeyPassword))
                    {
                        // Set the file.
                        _scp.AddIdentityFile(keyFile.PrivateKey, keyFile.PrivateKeyPassword);
                    }

                    // If a file exists.
                    if (!String.IsNullOrEmpty(keyFile.PrivateKey))
                    {
                        // Set the file.
                        _scp.AddIdentityFile(keyFile.PrivateKey);
                    }
                }
            }
            else
            {
                // If a password exists.
                if (!String.IsNullOrEmpty(sshConnection.Password))
                {
                    // Set the password.
                    _scp.Password = sshConnection.Password;
                }
            }

            // Set the events.
            _scp.OnTransferStart    += _sftp_OnTransferStart;
            _scp.OnTransferProgress += _sftp_OnTransferProgress;
            _scp.OnTransferEnd      += _sftp_OnTransferEnd;
        }
Example #3
0
        /// <summary>
        /// Secure shell host client.
        /// </summary>
        /// <param name="sshConnection">SSH connection adapter.</param>
        public SshClient(SshConnection sshConnection)
        {
            _sshConnection = sshConnection;

            // Get the authentication used.
            if (sshConnection.IsPrivateKeyAuthentication)
            {
                // Add the private key files.
                List <Renci.SshNet.PrivateKeyFile> privateKeyFile = new List <Renci.SshNet.PrivateKeyFile>();
                foreach (PrivateKeyFile keyFile in sshConnection.PrivateKeyFiles)
                {
                    privateKeyFile.Add(keyFile.SshNetPrivateKeyFile);
                }

                // If port number is 22 (default).
                if (sshConnection.Port == 22)
                {
                    _sshClient = new Renci.SshNet.SshClient(sshConnection.Host, sshConnection.Username, privateKeyFile.ToArray());
                }
                else
                {
                    _sshClient = new Renci.SshNet.SshClient(sshConnection.Host, sshConnection.Port, sshConnection.Username, privateKeyFile.ToArray());
                }
            }
            else
            {
                // If port number is 22 (default).
                if (sshConnection.Port == 22)
                {
                    _sshClient = new Renci.SshNet.SshClient(sshConnection.Host, sshConnection.Username, sshConnection.Password);
                }
                else
                {
                    _sshClient = new Renci.SshNet.SshClient(sshConnection.Host, sshConnection.Port, sshConnection.Username, sshConnection.Password);
                }
            }
        }