// ******************************************************************** // The createNewFolderToolStripMenuItem_Click function is triggered when the user right clicks the remote view and selects create folder // ******************************************************************** private void createNewFolderToolStripMenuItem_Click(object sender, EventArgs e) { try { dialogBox dialog = new dialogBox(); if (dialog.ShowDialog(this) == DialogResult.OK) { serverLogtxtbox.AppendText(dialog.nameTxtbox.Text + Environment.NewLine); newFolder = dialog.nameTxtbox.Text; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(("ftp://" + hostname + remotePathtsTxtBox.Text + "/" + newFolder).Replace(" /", "/")); request.KeepAlive = false; request.Method = WebRequestMethods.Ftp.MakeDirectory; request.Credentials = new NetworkCredential(username, password); if (transferType == "I") { request.UseBinary = true; } FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); reader = new StreamReader(responseStream); serverLogtxtbox.AppendText("Client: Sending command \"MKD "); serverLogtxtbox.AppendText("Server: " + response.StatusDescription); serverLogtxtbox.AppendText("Client: Creation of folder " + newFolder + " was successfull." + Environment.NewLine); selectedNode.Nodes.Clear(); List(remotePathtsTxtBox.Text); reader.Close(); response.Close(); } else { serverLogtxtbox.AppendText("Client: New folder creation canceled."); } } catch { const string message = "Failed to create a new folder."; MessageBox.Show(message, "Create New Folder Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// ******************************************************************** // The renameToolStripMenuItem_Click is triggered when the user right clicks a file/directory and selects rename // ******************************************************************** private void renameToolStripMenuItem_Click(object sender, EventArgs e) { try { dialogBox dialog = new dialogBox(); dialog.nameTxtbox.Text = selectedItem.SubItems[0].Text; if (dialog.ShowDialog(this) == DialogResult.OK) { renameto = dialog.nameTxtbox.Text; serverLogtxtbox.AppendText("ftp://" + hostname + remotePathtsTxtBox.Text + "/" + renameto + Environment.NewLine); FtpWebRequest request = (FtpWebRequest)WebRequest.Create(("ftp://" + hostname + remotePathtsTxtBox.Text + "/" + selectedItem.SubItems[0].Text).Replace(" /", "/")); request.KeepAlive = false; request.Method = WebRequestMethods.Ftp.Rename; request.RenameTo = renameto; request.Credentials = new NetworkCredential(username, password); if (transferType == "I") { request.UseBinary = true; } FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); reader = new StreamReader(responseStream); serverLogtxtbox.AppendText("Client: Send command \"RENAME & RENAMETO\" commands." + Environment.NewLine); serverLogtxtbox.AppendText("Server: " + response.StatusDescription); serverLogtxtbox.AppendText("Client: Renaming of file " + selectedItem.SubItems[0].Text + " to " + renameto + " was successfull." + Environment.NewLine); selectedNode.Nodes.Clear(); List(remotePathtsTxtBox.Text); reader.Close(); response.Close(); } } catch { const string message = "Failed to rename the file or directory to the new name. Please try again."; MessageBox.Show(message, "File/Directory Renaming Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }