📄 ftpexplorerdlg.cs
字号:
this.toolBar1.Size = new System.Drawing.Size(427, 31);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.OnButtonClickToolBar);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.ToolTipText = "Connect to FTP server";
//
// toolBarButton4
//
this.toolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton5
//
this.toolBarButton5.ImageIndex = 3;
this.toolBarButton5.ToolTipText = "Create Folder in Remote Server";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 4;
this.toolBarButton6.ToolTipText = "Delete a folder in Remote Server";
//
// toolBarButton7
//
this.toolBarButton7.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton10
//
this.toolBarButton10.ImageIndex = 7;
this.toolBarButton10.ToolTipText = "Download file from Remote Server";
//
// toolBarButton11
//
this.toolBarButton11.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton12
//
this.toolBarButton12.ImageIndex = 8;
this.toolBarButton12.ToolTipText = "Delete a file in Remote server";
//
// toolBarButton13
//
this.toolBarButton13.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton14
//
this.toolBarButton14.ImageIndex = 9;
this.toolBarButton14.ToolTipText = "Set Local folder";
//
// toolBarButton15
//
this.toolBarButton15.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButton17
//
this.toolBarButton17.ImageIndex = 10;
this.toolBarButton17.ToolTipText = "Close this window";
//
// m_sbStatus
//
this.m_sbStatus.Location = new System.Drawing.Point(0, 267);
this.m_sbStatus.Name = "m_sbStatus";
this.m_sbStatus.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanel1,
this.statusBarPanel2,
this.statusBarPanel3});
this.m_sbStatus.ShowPanels = true;
this.m_sbStatus.Size = new System.Drawing.Size(427, 20);
this.m_sbStatus.TabIndex = 0;
this.m_sbStatus.Text = "statusBar1";
//
// m_dGFiles
//
this.m_dGFiles.CaptionVisible = false;
this.m_dGFiles.DataMember = "";
this.m_dGFiles.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_dGFiles.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.m_dGFiles.Location = new System.Drawing.Point(263, 31);
this.m_dGFiles.Name = "m_dGFiles";
this.m_dGFiles.ReadOnly = true;
this.m_dGFiles.Size = new System.Drawing.Size(164, 236);
this.m_dGFiles.TabIndex = 5;
this.toolTip1.SetToolTip(this.m_dGFiles, "Displays files in the FTP Server");
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(260, 31);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 236);
this.splitter1.TabIndex = 4;
this.splitter1.TabStop = false;
//
// m_lVFiles
//
this.m_lVFiles.Dock = System.Windows.Forms.DockStyle.Fill;
this.m_lVFiles.Location = new System.Drawing.Point(260, 31);
this.m_lVFiles.Name = "m_lVFiles";
this.m_lVFiles.Size = new System.Drawing.Size(167, 236);
this.m_lVFiles.TabIndex = 3;
this.toolTip1.SetToolTip(this.m_lVFiles, "Displays Files in FTP Server");
this.m_lVFiles.Visible = false;
//
// m_tVFolders
//
this.m_tVFolders.Dock = System.Windows.Forms.DockStyle.Left;
this.m_tVFolders.ImageList = this.m_iLTreeView;
this.m_tVFolders.Location = new System.Drawing.Point(0, 31);
this.m_tVFolders.Name = "m_tVFolders";
this.m_tVFolders.Size = new System.Drawing.Size(260, 236);
this.m_tVFolders.TabIndex = 2;
this.toolTip1.SetToolTip(this.m_tVFolders, "Displays Folders in FTP Server");
this.m_tVFolders.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.OnAfterSelectFolderView);
//
// m_iLTreeView
//
this.m_iLTreeView.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.m_iLTreeView.ImageSize = new System.Drawing.Size(16, 16);
this.m_iLTreeView.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("m_iLTreeView.ImageStream")));
this.m_iLTreeView.TransparentColor = System.Drawing.Color.Transparent;
//
// FTPExplorerDlg
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(427, 287);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.m_dGFiles,
this.splitter1,
this.m_lVFiles,
this.m_tVFolders,
this.toolBar1,
this.m_sbStatus});
this.Name = "FTPExplorerDlg";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FTP Explorer - Not connected";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Closing += new System.ComponentModel.CancelEventHandler(this.OnFormClosing);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanel2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.m_dGFiles)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void OnClickServerConnect(object sender, System.EventArgs e) {
FTPConnectDlg connectDlg = new FTPConnectDlg(m_FTPProperties);
if ( connectDlg.ShowDialog() == DialogResult.OK){
SetStatusMessage("Connecting to server. Please wait...","","NONE");
Cursor = Cursors.WaitCursor;
m_FTPProperties = connectDlg.m_FTPProperties;
m_FTPProperties.FTPServer = connectDlg.FTPServer;
m_FTPProperties.UserID = connectDlg.UserID;
m_FTPProperties.Password = connectDlg.Password;
if ( m_FtpClient == null ){
m_FtpClient = new FTPClient(m_FTPProperties.FTPServer,m_FTPProperties.UserID,m_FTPProperties.Password,m_FTPProperties.Port,m_FTPProperties.SendTimeOut,m_FTPProperties.RecvTimeOut);
}
else {
m_FtpClient.FTPServer = m_FTPProperties.FTPServer;
m_FtpClient.UserID = m_FTPProperties.UserID;
m_FtpClient.Password = m_FTPProperties.Password;
m_FtpClient.Port = m_FTPProperties.Port;
m_FtpClient.SendTimeOut = m_FTPProperties.SendTimeOut;
m_FtpClient.RecvTimeOut = m_FTPProperties.RecvTimeOut;
}
int l_iRetval = m_FtpClient.Connect();
if ( l_iRetval == 0 ){
Cursor = Cursors.Arrow;
MessageBox.Show(m_FtpClient.ErrorMessage,"FTP Explorer - Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
return ;
}
EnableToolBarButtons(true);
string l_strTemp = m_FTPProperties.UserID + "@" + m_FTPProperties.FTPServer;
SetStatusMessage("Connected to " + l_strTemp,"Listing foldes and files. Please wait...","NONE");
/* Proceed with Listing files */
DataTable l_dtFileList = m_FtpClient.GetList(null);
if ( l_dtFileList != null && l_dtFileList.Rows.Count > 0 ){
m_tnRootNode = new TreeNode(m_FtpClient.RootDirectory,0,0);
m_tVFolders.Nodes.Add(m_tnRootNode);
PopulateFolders(m_tnRootNode,l_dtFileList);
PopulateFiles(l_dtFileList);
}
else {
Cursor = Cursors.Arrow;
/* If error then disconnect */
MessageBox.Show(m_FtpClient.ErrorMessage,"FTP Explorer - Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
OnClickServerDisconnect(sender,e);
return;
}
this.Text = l_strTemp;
Cursor = Cursors.Arrow;
}
}
private void OnClickServerDisconnect(object sender, System.EventArgs e) {
m_FtpClient.Disconnect();
m_tVFolders.Nodes.Clear();
m_dGFiles.DataSource = null;
m_dGFiles.DataBindings.Clear();
m_dGFiles.Refresh();
EnableToolBarButtons(false);
SetStatusMessage("Not Connected","",m_strLocalFolder);
this.Text = "Not connected";
}
private void OnClickServerConfigure(object sender, System.EventArgs e) {
FTPConfigureDlg configureDlg = new FTPConfigureDlg(false,m_FTPProperties);
if ( configureDlg.ShowDialog() == DialogResult.OK){
m_FTPProperties = configureDlg.m_FTPProperties;
}
}
private void OnButtonClickToolBar(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) {
int l_iImageIndex = e.Button.ImageIndex;
switch (l_iImageIndex){
case 0 :
OnClickServerConnect(sender,e);
break;
case 1:
OnClickServerDisconnect(sender,e);
break;
case 2:
OnClickServerConfigure(sender,e);
break;
case 3:
OnClickOptionsCreateFolder(sender,e);
break;
case 4:
OnClickOptionsDeleteFolder(sender,e);
break;
case 5 :
OnClickOptionsRefresh(sender,e);
break;
case 6 :
OnClickOptionsUploadFile(sender,e);
break;
case 7 :
OnClickOptionsDownloadFile(sender,e);
break;
case 8 :
OnClickOptionsDeleteFile(sender,e);
break;
case 9 :
OnClickOptionsSetLWD(sender,e);
break;
case 10 :
OnClickClose(sender,e);
break;
default :
break;
}
}
private void InitControls(){
m_tVFolders.Nodes.Clear();
m_lVFiles.Items.Clear();
m_iFolderCount = m_iFileCount = 0;
SetStatusMessage("Not Connected","",m_strLocalFolder);
return;
}
private void OnClickOptionsCreateFolder(object sender, System.EventArgs e) {
string l_strNewFolder = "";
FTPNewFolderDlg newFolderDlg = new FTPNewFolderDlg();
if ( newFolderDlg.ShowDialog() == DialogResult.OK){
this.Cursor = Cursors.WaitCursor;
l_strNewFolder = newFolderDlg.NewFolder;
int l_iRetval = m_FtpClient.CreateFolder(l_strNewFolder);
if ( l_iRetval == 0 ) {
this.Cursor = Cursors.Arrow;
string l_strError = m_FtpClient.ErrorMessage;
MessageBox.Show(l_strError,"FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Stop);
return;
}
else {
/* Add the node to tree view control */
TreeNode l_tnCurrNode = m_tVFolders.SelectedNode;
TreeNodeCollection l_tcNodes = l_tnCurrNode.Nodes;
TreeNode l_tnChildNode = new TreeNode(l_strNewFolder,1,2);
l_tcNodes.Add(l_tnChildNode);
m_tVFolders.Refresh();
/* Select the current node */
m_bNewNodeFlag = true;
m_tVFolders.SelectedNode = l_tnChildNode;
/* Clear the File View */
m_dGFiles.DataSource = null;
m_dGFiles.DataBindings.Clear();
SetStatusMessage("NONE","Folder(s) :0, File(s) :0","NONE");
this.Cursor = Cursors.Arrow;
//MessageBox.Show("Folder '" + l_strNewFolder + "' Successfully created","FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}
private void OnClickOptionsDeleteFolder(object sender, System.EventArgs e) {
TreeNode l_tnCurrNode = m_tVFolders.SelectedNode;
if ( m_tVFolders.ContainsFocus == false ) {
MessageBox.Show("Select a folder to be deleted and select this option","FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
if ( l_tnCurrNode == null ) {
MessageBox.Show("Select a folder other than root node to delete","FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
if ( l_tnCurrNode == m_tnRootNode ) {
MessageBox.Show("Cannot remove root node","FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
string l_strFolder = l_tnCurrNode.FullPath;
l_strFolder = l_strFolder.Replace('\\','/');
string l_strMessage = "Are you sure to delete '" + l_strFolder + "' folder ?";
if ( MessageBox.Show(l_strMessage,"FTP Explorer",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) != DialogResult.OK ) {
return;
}
statusBarPanel2.Text = "Deleting selected folder. Please wait...";
m_sbStatus.Refresh();
this.Cursor = Cursors.WaitCursor;
TreeNode l_tnParentNode = l_tnCurrNode.Parent;
if ( l_tnParentNode == null ) {
l_tnParentNode = m_tnRootNode;
}
/* Go to parent folder and then delete the current folder */
string l_strParentFolder = l_tnParentNode.FullPath;
l_strParentFolder = l_strParentFolder.Replace('\\','/');
int l_iRetval = m_FtpClient.ChangeWorkingFolder(l_strParentFolder);
if (l_iRetval == 0 ) {
this.Cursor = Cursors.Arrow;
string l_strErr = m_FtpClient.ErrorMessage;
MessageBox.Show(l_strErr,"FTP Explorer",MessageBoxButtons.OK,MessageBoxIcon.Error);
return ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -