To() public method

Copies a file from local machine to a remote SSH machine.
public To ( string localPath, string remotePath ) : void
localPath string The local file path.
remotePath string The path of the remote file.
return void
示例#1
0
        protected void PutDirectory(string host, NodeAuth auth, string local, string remote)
        {
            Scp scp = new Scp (host, auth.UserName);

            SetupSSH (scp, auth);

            scp.To (local, remote, true);
            scp.Close ();
        }
示例#2
0
        public void SFtpUpload()
        {
            string remoteFilename = string.Format("{0}/{1}", _remoteDirectory, _remoteFilename);

            //Create a new SCP instance
            Scp scp = new Scp();

            //Copy a file from local machine to remote SSH server
            scp.To(_localFilename, _remoteHost, remoteFilename, _user, _password);
        }
        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;
            }
        }
        public static void Upload(string filename, string path)
        {
            if (Convert.ToBoolean(ConfigurationManager.AppSettings.Get("EnableSCP")))
            {
                string host = ConfigurationManager.AppSettings.Get("SCPDirectory");
                string user = ConfigurationManager.AppSettings.Get("SCPLogin");
                string password = ConfigurationManager.AppSettings.Get("SCPPassword");
                string newDirectory = "/home/honeybadgers/public_html/Music Files/" + Globals.UserID + "/";

                //Create a new SCP instance
                Scp scp = new Scp(host, user, password);

                scp.Connect();
                scp.Mkdir(newDirectory);

                //Copy a file from local machine to remote SSH server
                scp.To(path, newDirectory + filename);
            }
        }
示例#5
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");
        }