Esempio n. 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            // khi nhấn nút rename
            string newName = txtNewName.Text;

            using (Ftp client = new Ftp())
            {
                // kết nối đến server FTP
                client.Connect(_ip, _port);
                client.Login(_username, _password);

                // nếu là tập tin
                if (_type == "Là tập tin")
                {
                    // lấy tên tập tin
                    string oldName    = txtOldName.Text;
                    var    name       = oldName.Split('.');             // thực thi phương thức split cắt ra ở dấu . đuôi mở rộng
                    string duoiMoRong = name[1];                        // lấy phần mở rộng để lát gán lại ở giá trị mới

                    client.Rename(oldName, newName + "." + duoiMoRong); // thực thi phương thức rename
                }
                // nếu là thư mục thì đổi tên thẳng không cần split
                else if (_type == "Là thư mục")
                {
                    client.Rename(txtOldName.Text, newName);
                }
                // in câu thông báo hoàn tất
                MessageBox.Show("Đổi tên hoàn tất.");
                txtOldName.Text = "";
                txtNewName.Text = "";
                client.Close();
            }
        }