void deleteItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string strRemotePath = ""; if (clickedItem.Text.Equals("Delete")) { strRemotePath = remoteTreeView.SelectedNode.FullPath; DialogResult deleteResult = MessageBox.Show("Delete will be Permanent. Continue?", "Please Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (deleteResult == DialogResult.Yes) { Ftp ftpClient = new Ftp(strHost, strUser, strPass); if (checkIsFile(remoteTreeView.SelectedNode.Text)) { ftpClient.delete(strRemotePath); } else { ftpClient.deleteDirectory(strRemotePath); } populateRemoteNode(remoteTreeView.SelectedNode.Parent); remoteTreeView.SelectedNode.Parent.Expand(); ftpClient = null; remoteTreeView.Refresh(); } } }
void renameItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string strRemotePath = ""; if (clickedItem.Text.Equals("Rename")) { strRemotePath = remoteTreeView.SelectedNode.FullPath; using (RenameForm renameForm = new RenameForm()) { if (renameForm.ShowDialog() == DialogResult.OK) { try { Cursor.Current = Cursors.WaitCursor; string strNewFileName = renameForm.newFileName; Ftp ftpClient = new Ftp(strHost, strUser, strPass); ftpClient.rename(strRemotePath, strNewFileName); ftpClient = null; populateRemoteNode(remoteTreeView.SelectedNode.Parent); remoteTreeView.SelectedNode.Parent.Expand(); Cursor.Current = Cursors.Default; MessageBox.Show("File Rename Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("File Rename Unsuccessful\n" + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void connectBtn_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (hostNameTxtBox.Text == "" || userNameTxtBox.Text == "" || passwrdTxtBox.Text == "") { MessageBox.Show("Please Enter Connection Details"); return; } else { if (portTextBox.Text == "") { strHost = "ftp://" + hostNameTxtBox.Text; } else { strHost = "ftp://" + hostNameTxtBox.Text + ":" + portTextBox.Text; } strUser = userNameTxtBox.Text; strPass = passwrdTxtBox.Text; Ftp ftpClient = new Ftp(strHost, strUser, strPass); remoteTreeView.Nodes.Clear(); try { string[] remoteContents = ftpClient.directoryList("/"); foreach (string strRemote in remoteContents) { if (strRemote == "") { break; } else { TreeNode node = new TreeNode(strRemote); node.Tag = strRemote; if (!checkIsFile(node.Text)) { node.ImageIndex = -1; node.SelectedImageIndex = 1; } else { node.ImageIndex = 2; } remoteTreeView.Nodes.Add(node); } } remotePathLabel.Text = "/"; } catch (Exception ex) { MessageBox.Show("Error Retrieving Remote Files.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ftpClient = null; } Cursor.Current = Cursors.Default; }
private void downloadBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; string[] args = e.Argument as string[]; string remoteFile = args[0]; string localFile = args[1]; Ftp ftp = new Ftp(strHost, strUser, strPass); ftp.download(remoteFile, localFile, worker, e); ftp = null; }
private void uploadBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; // Assign the result of the computation // to the Result property of the DoWorkEventArgs // object. This is will be available to the // RunWorkerCompleted eventhandler. string[] args = e.Argument as string[]; string remoteFile = args[0]; string localFile = args[1]; Ftp ftp = new Ftp(strHost, strUser, strPass); ftp.upload(remoteFile, localFile, worker, e); ftp = null; }
private void populateRemoteNode(TreeNode node) { try { Ftp ftpClient = new Ftp(strHost, strUser, strPass); string[] remoteContents = ftpClient.directoryList("/" + node.FullPath + "/"); node.Nodes.Clear(); foreach (string strRemote in remoteContents) { if (strRemote == "") { break; } else { node.Nodes.Add(strRemote); } } foreach (TreeNode childNode in node.Nodes) { if (!checkIsFile(childNode.Text)) { childNode.ImageIndex = -1; childNode.SelectedImageIndex = 1; } else { childNode.ImageIndex = 2; childNode.SelectedImageIndex = 2; } } node.Expand(); ftpClient = null; } catch (Exception ex) { MessageBox.Show("Error Retrieving Remote Contents\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void fileInfoItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string currentFile = remoteTreeView.SelectedNode.FullPath; string[] fileInfo; try { Cursor.Current = Cursors.WaitCursor; Ftp ftpClient = new Ftp(strHost, strUser, strPass); fileInfo = ftpClient.getFileSize(currentFile); ftpClient = null; Cursor.Current = Cursors.Default; MessageBox.Show("File Size: " + fileInfo[0] + "\nDate Last Modified: " + fileInfo[1], "File Information"); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Failure to retrieve File Information\n" + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void createDirectoryItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string newDirectory = remoteTreeView.SelectedNode.FullPath; if (clickedItem.Text.Equals("Create Directory")) { using (CreateRemoteDirectoryForm newDirectoryForm = new CreateRemoteDirectoryForm()) { if (newDirectoryForm.ShowDialog() == DialogResult.OK) { try { Cursor.Current = Cursors.WaitCursor; string strNewDirectoryName = newDirectoryForm.newDirectoryName; newDirectory += "/" + strNewDirectoryName; Ftp ftpClient = new Ftp(strHost, strUser, strPass); ftpClient.createRemoteDirectory(newDirectory); ftpClient = null; populateRemoteNode(remoteTreeView.SelectedNode); remoteTreeView.SelectedNode.Expand(); Cursor.Current = Cursors.Default; MessageBox.Show("Directory Creation Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Directory Creation Unsuccessful\n" + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void connectBtn_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (hostNameTxtBox.Text == "" || userNameTxtBox.Text == "" || passwrdTxtBox.Text == "") { MessageBox.Show("Please Enter Connection Details"); return; } else { if(portTextBox.Text == "") strHost = "ftp://" + hostNameTxtBox.Text; else strHost = "ftp://" + hostNameTxtBox.Text + ":" + portTextBox.Text; strUser = userNameTxtBox.Text; strPass= passwrdTxtBox.Text; Ftp ftpClient = new Ftp(strHost, strUser, strPass); remoteTreeView.Nodes.Clear(); try { string[] remoteContents = ftpClient.directoryList("/"); foreach (string strRemote in remoteContents) { if (strRemote == "") { break; } else { TreeNode node = new TreeNode(strRemote); node.Tag = strRemote; if (!checkIsFile(node.Text)) { node.ImageIndex = -1; node.SelectedImageIndex = 1; } else { node.ImageIndex = 2; } remoteTreeView.Nodes.Add(node); } } remotePathLabel.Text = "/"; } catch (Exception ex) { MessageBox.Show("Error Retrieving Remote Files.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } ftpClient = null; } Cursor.Current = Cursors.Default; }
private void uploadBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; // Assign the result of the computation // to the Result property of the DoWorkEventArgs // object. This is will be available to the // RunWorkerCompleted eventhandler. string[] args = e.Argument as string[]; string remoteFile = args[0]; string localFile = args[1]; Ftp ftp = new Ftp(strHost,strUser,strPass); ftp.upload(remoteFile,localFile, worker, e); ftp = null; }
void renameItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string strRemotePath =""; if (clickedItem.Text.Equals("Rename")) { strRemotePath = remoteTreeView.SelectedNode.FullPath; using (RenameForm renameForm = new RenameForm()) { if (renameForm.ShowDialog() == DialogResult.OK) { try { Cursor.Current = Cursors.WaitCursor; string strNewFileName = renameForm.newFileName; Ftp ftpClient = new Ftp(strHost, strUser, strPass); ftpClient.rename(strRemotePath, strNewFileName); ftpClient = null; populateRemoteNode(remoteTreeView.SelectedNode.Parent); remoteTreeView.SelectedNode.Parent.Expand(); Cursor.Current = Cursors.Default; MessageBox.Show("File Rename Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("File Rename Unsuccessful\n" + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
void deleteItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string strRemotePath = ""; if (clickedItem.Text.Equals("Delete")) { strRemotePath = remoteTreeView.SelectedNode.FullPath; DialogResult deleteResult = MessageBox.Show("Delete will be Permanent. Continue?","Please Confirm Delete", MessageBoxButtons.YesNo,MessageBoxIcon.Warning); if (deleteResult == DialogResult.Yes) { Ftp ftpClient = new Ftp(strHost, strUser, strPass); if (checkIsFile(remoteTreeView.SelectedNode.Text)) ftpClient.delete(strRemotePath); else ftpClient.deleteDirectory(strRemotePath); populateRemoteNode(remoteTreeView.SelectedNode.Parent); remoteTreeView.SelectedNode.Parent.Expand(); ftpClient = null; remoteTreeView.Refresh(); } } }
void createDirectoryItem_Click(object sender, EventArgs e) { ToolStripItem clickedItem = sender as ToolStripItem; string newDirectory = remoteTreeView.SelectedNode.FullPath; if (clickedItem.Text.Equals("Create Directory")) { using(CreateRemoteDirectoryForm newDirectoryForm = new CreateRemoteDirectoryForm()) { if(newDirectoryForm.ShowDialog() == DialogResult.OK) { try { Cursor.Current = Cursors.WaitCursor; string strNewDirectoryName = newDirectoryForm.newDirectoryName; newDirectory += "/" + strNewDirectoryName; Ftp ftpClient = new Ftp(strHost, strUser, strPass); ftpClient.createRemoteDirectory(newDirectory); ftpClient = null; populateRemoteNode(remoteTreeView.SelectedNode); remoteTreeView.SelectedNode.Expand(); Cursor.Current = Cursors.Default; MessageBox.Show("Directory Creation Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch(Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show("Directory Creation Unsuccessful\n" + ex.Message, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }