Example #1
0
        private void UploadFile(string fname)
        {
            SshTransferProtocolBase sshCp = null;

            if (ProgramSettings.settings.SshKey.Length == 0)
            {
                sshCp = new Scp(ProgramSettings.settings.SshHost, ProgramSettings.settings.SshLogin, ProgramSettings.settings.SshPass);
            }
            else
            {
                try
                {
                    sshCp = new Scp(ProgramSettings.settings.SshHost, ProgramSettings.settings.SshLogin);
                    if (ProgramSettings.settings.SshPass.Length == 0)
                    {
                        sshCp.AddIdentityFile(ProgramSettings.settings.SshKey);
                    }
                    else
                    {
                        sshCp.AddIdentityFile(ProgramSettings.settings.SshKey, ProgramSettings.settings.SshPass);
                    }
                }
                catch {}
            }
            sshCp.Connect(ProgramSettings.settings.SshPort);
            sshCp.Put(fname, ProgramSettings.settings.LstDir + "/" + fname);
            sshCp.Close();
            return;
        }
Example #2
0
        private void btnTransfer_Click(object sender, EventArgs e)
        {
            if (host_input.Text == "")
            {
                MessageBox.Show("Please input a Host.", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (user_input.Text == "")
            {
                MessageBox.Show("Please input a User.", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Scp sshCp = new Scp(host_input.Text, user_input.Text);

            if (password_input.Text != "")
            {
                sshCp.Password = password_input.Text;
            }
            else if (privatekey_input.FileName != "")
            {
                sshCp.AddIdentityFile(privatekey_input.FileName);
            }
            else
            {
                MessageBox.Show("Please input a password or private key file.", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (serverlocation_input.Text == "")
            {
                MessageBox.Show("Please input a Server Side location to store the file.", "Incomplete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            sshCp.OnTransferStart    += new FileTransferEvent(sshCp_OnTransferStart);
            sshCp.OnTransferProgress += new FileTransferEvent(sshCp_OnTransferProgress);
            sshCp.OnTransferEnd      += new FileTransferEvent(sshCp_OnTransferEnd);

            sshCp.Connect();

            string destination = serverlocation_input.Text;

            if (!destination.EndsWith("/"))
            {
                destination += '/';
            }
            destination += "dnadata/" + this.dest_folder;

            sshCp.To(this.interface_folder, destination, true);

            sshCp.Close();

            MessageBox.Show("Transfer complete!", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #3
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;
        }