Exemple #1
0
        private void ApplyButton_Click(object sender, EventArgs e)
        {
            if (DefaultIP.Text == "" ||
                DefaultGW.Text == "" ||
                DefaultSN.Text == "" ||
                NewIP.Text == "" ||
                NewGW.Text == "" ||
                NewSN.Text == ""
                )
            {
                MessageBox.Show("All variables must have a value", "Error");
                return;
            }

            host = DefaultIP.Text;

            string fileName = string.Empty;

            fileName = Path.GetTempFileName();
            FileInfo fileInfo = new FileInfo(fileName);

            fileInfo.Attributes = FileAttributes.Temporary;

            string fullPath = Path.GetTempFileName();

            StreamWriter streamWriter = File.AppendText(fullPath);

            streamWriter.WriteLine(Properties.Resources.rc);
            streamWriter.Flush();
            streamWriter.Close();

            //MessageBox.Show(fullPath);

            string local = fullPath, remote = "disk/etc/rc";

            ReplaceInFile(local, "10.0.1.230", DefaultIP.Text);
            ReplaceInFile(local, "255.255.255.0", DefaultSN.Text);
            ReplaceInFile(local, "10.0.1.1", DefaultGW.Text);

            ReplaceInFile(local, DefaultIP.Text, NewIP.Text);
            ReplaceInFile(local, DefaultSN.Text, NewSN.Text);
            ReplaceInFile(local, DefaultGW.Text, NewGW.Text);
            try
            {
                Scp scp = new Scp();
                scp.To(local, host, remote, user, pass);
            }
            catch
            {
                string error = "Cannot connect to controller at " + DefaultIP.Text;
                MessageBox.Show(error, "Error");
                return;
            }
            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }

            MessageBox.Show("You must reboot the controller for IP changes to take effect.", "Important");
        }
Exemple #2
0
        void StartToUpload()
        {
            try {
                mScp = new Scp(mServerIP, mUsername, mPassword);
                mScp.OnTransferStart    += SshCp_OnTransferStart;
                mScp.OnTransferProgress += SshCp_OnTransferProgress;
                mScp.OnTransferEnd      += SshCp_OnTransferEnd;
                mScp.Connect();

                if (Directory.Exists(mSrcFolder))
                {
                    mScp.Recursive = true;
                    mFileCount     = GetFileCount(mSrcFolder);
                }
                else
                {
                    mScp.Recursive = false;
                    mFileCount     = 1;
                }

                mScp.To(mSrcFolder, mDesFolder);
            } catch (System.Exception e) {
                Debug.LogError("Start scp exception : " + e.Message);
                Reset();
            }
        }
Exemple #3
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);
        }
Exemple #4
0
 /// <summary>
 /// Copies a file from local machine to a remote SSH machine.
 /// </summary>
 /// <param name="localPath">The local file path.</param>
 /// <param name="remotePath">The path of the remote file.</param>
 /// <param name="recursive">Indicating whether a recursive transfer should take place.</param>
 public void To(string localPath, string remotePath, bool recursive = false)
 {
     if (_scp.Connected)
     {
         // Receive the data.
         _scp.To(localPath, remotePath, recursive);
     }
     else
     {
         throw new Exception("An active connection does not exist.");
     }
 }
Exemple #5
0
        /// <summary>
        /// Demonstrates the Scp class
        /// </summary>
        /// <param name="cmd">Either "to" or "from"</param>
        public static void Scp(string cmd)
        {
            GetInput();

            string local = null, remote = null;

            if (cmd.ToLower().Equals("to"))
            {
                Console.Write("Local file: ");
                local = Console.ReadLine();
                Console.Write("Remote file: ");
                remote = Console.ReadLine();
            }
            else if (cmd.ToLower().Equals("from"))
            {
                Console.Write("Remote file: ");
                remote = Console.ReadLine();
                Console.Write("Local file: ");
                local = Console.ReadLine();
            }

            Scp scp = new Scp();

            scp.OnConnecting += new FileTansferEvent(scp_OnConnecting);
            scp.OnStart      += new FileTansferEvent(scp_OnProgress);
            scp.OnEnd        += new FileTansferEvent(scp_OnEnd);
            scp.OnProgress   += new FileTansferEvent(scp_OnProgress);

            try
            {
                if (cmd.ToLower().Equals("to"))
                {
                    scp.To(local, host, remote, user, pass);
                }
                else if (cmd.ToLower().Equals("from"))
                {
                    scp.From(host, remote, user, pass, local);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemple #6
0
        public static void TransferFileToMachine(string localFilePath, string remoteFilePath)
        {
            try
            {
                //Create a new SCP instance
                Scp scp = new Scp(MACHINE_IP, USER_NAME, PASSWORD);

                scp.Connect();

                //Copy a file from remote SSH server to local machine
                scp.To(localFilePath, remoteFilePath);

                scp.Close();
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #7
0
        }     // end BajarSCP

        public static void SubirSCP(string pServidor, string pUsuario, string pPassword, string pFileRemoto, string pFileLocal)
        {
            // instancia del objeto SCP
            Scp SCP = new Scp(pServidor, pUsuario, pPassword);

            try
            {
                // crear conexion SSH
                SCP.Connect();
                // Subir el archivo
                SCP.To(pFileLocal, pFileRemoto, false);
            }
            catch (Exception ex)
            { throw ex; }
            finally
            {
                //cerrar conexion SCP
                SCP.Close();
            } // end try
        }     // end SubirSCP