⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 explorerdlg.cs

📁 用C#写的FTP客户端
💻 CS
📖 第 1 页 / 共 3 页
字号:
/*	Project		:	FTPExplorer
 *	File Name	:	ExplorerDlg.cs
 *	Purpose		:	Main application window
 *	Author		:	K.Niranjan Kumar
 *	Date		:	07/05/2001
 *	Company		:	Cognizant Technology Solutions.
 *	e-Mail		:	KNiranja@chn.cognizant.com
 */

namespace FTPExplorer
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;
	using System.IO;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class ExplorerDlg : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.MenuItem m_menuMRU4;
		private System.WinForms.MenuItem m_menuMRU3;
		private System.WinForms.MenuItem m_menuMRU2;
		private System.WinForms.MenuItem m_menuMRUSep;
		private System.WinForms.MenuItem m_menuMRU1;
		public System.WinForms.ProgressBar m_progressBarFileStatus;
		private System.WinForms.StatusBarPanel statusBarPanel3;
		private System.WinForms.ToolBarButton toolBarButton12;
		private System.WinForms.MenuItem menuItem18;
		private System.WinForms.MenuItem menuItem16;
		private System.WinForms.ToolTip m_toolTip;
		private System.WinForms.ImageList m_imageListTreeView;
		private System.WinForms.GroupBox groupBox1;
		private System.WinForms.Label m_labelListView;
		private System.WinForms.Label m_labelTreeView;
		private System.WinForms.ToolBarButton toolBarButton11;
		private System.WinForms.ToolBarButton toolBarButton10;
		private System.WinForms.ToolBarButton toolBarButton9;
		private System.WinForms.ToolBarButton toolBarButton8;
		private System.WinForms.ImageList m_imageListToolBar;
		private System.WinForms.StatusBarPanel statusBarPanel2;
		private System.WinForms.StatusBarPanel statusBarPanel1;
		private System.WinForms.StatusBar m_statusBar;
		private System.WinForms.ListView m_lvFileView;
		private System.WinForms.TreeView m_tvFolderView;
		private System.WinForms.ToolBarButton toolBarButton7;
		private System.WinForms.ToolBarButton toolBarButton6;
		private System.WinForms.ToolBarButton toolBarButton5;
		private System.WinForms.ToolBarButton toolBarButton4;
		private System.WinForms.ToolBarButton toolBarButton3;
		private System.WinForms.ToolBarButton toolBarButton2;
		private System.WinForms.ToolBarButton toolBarButton1;
		private System.WinForms.ToolBar m_toolBar;
		private System.WinForms.MenuItem menuItem15;
		private System.WinForms.MenuItem menuItem11;
		private System.WinForms.MenuItem menuItem5;
		private System.WinForms.MenuItem menuItem14;
		private System.WinForms.MenuItem menuItem13;
		private System.WinForms.MenuItem menuItem10;
		private System.WinForms.MenuItem menuItem9;
		private System.WinForms.MenuItem menuItem8;
		private System.WinForms.MenuItem menuItem4;
		private System.WinForms.MenuItem menuItem3;
		private System.WinForms.MenuItem menuItem2;
		private System.WinForms.MenuItem menuItem1;
		private System.WinForms.MainMenu m_mainMenu;


		/*	Our members */
		private FTPClient m_FTPClient;
		private bool m_bConnectedFlag ;
		private TreeNode m_tnRootNode;
		private string m_strFTPAddress;
		private string m_strFTPUser;
		private string m_strFTPPassword;
		private string m_strLocalDirectory;

		private MRUConnections[] m_arrMRUConn;
		private int m_iMRUCount;

        public ExplorerDlg()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
			
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
			m_FTPClient = new FTPClient();
			m_bConnectedFlag = false;
			m_strFTPAddress = "";
			m_strFTPUser = "";
			m_strFTPPassword = "";
			ToggleMenuItems(0);
			InitControls();
			m_tnRootNode = null;
			m_strLocalDirectory = "C:\\";		/*	C:\ is the default Local directory	*/
			m_FTPClient.ParentWindow = this;
			m_arrMRUConn = new MRUConnections[4];
			m_iMRUCount = 0;
			/*	Fill in the arrays */
			m_arrMRUConn[0] = new MRUConnections();
			m_arrMRUConn[1] = new MRUConnections();
			m_arrMRUConn[2] = new MRUConnections();
			m_arrMRUConn[3] = new MRUConnections();
		}

		private void InitControls(){
			m_labelTreeView.Text = "No folders to display";
			m_labelListView.Text = "No files to display";
			statusBarPanel1.Text = "Not Connected";
			statusBarPanel2.Text = "";
			statusBarPanel3.Text = m_strLocalDirectory;
		}

        /// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof(ExplorerDlg));
			this.components = new System.ComponentModel.Container ();
			this.menuItem18 = new System.WinForms.MenuItem ();
			this.m_labelListView = new System.WinForms.Label ();
			this.menuItem15 = new System.WinForms.MenuItem ();
			this.groupBox1 = new System.WinForms.GroupBox ();
			this.menuItem14 = new System.WinForms.MenuItem ();
			this.m_toolBar = new System.WinForms.ToolBar ();
			this.toolBarButton12 = new System.WinForms.ToolBarButton ();
			this.toolBarButton11 = new System.WinForms.ToolBarButton ();
			this.m_toolTip = new System.WinForms.ToolTip (this.components);
			this.m_menuMRU2 = new System.WinForms.MenuItem ();
			this.m_labelTreeView = new System.WinForms.Label ();
			this.m_menuMRU1 = new System.WinForms.MenuItem ();
			this.toolBarButton7 = new System.WinForms.ToolBarButton ();
			this.toolBarButton4 = new System.WinForms.ToolBarButton ();
			this.toolBarButton6 = new System.WinForms.ToolBarButton ();
			this.menuItem16 = new System.WinForms.MenuItem ();
			this.toolBarButton1 = new System.WinForms.ToolBarButton ();
			this.toolBarButton5 = new System.WinForms.ToolBarButton ();
			this.m_menuMRU3 = new System.WinForms.MenuItem ();
			this.m_progressBarFileStatus = new System.WinForms.ProgressBar ();
			this.m_tvFolderView = new System.WinForms.TreeView ();
			this.m_menuMRU4 = new System.WinForms.MenuItem ();
			this.statusBarPanel3 = new System.WinForms.StatusBarPanel ();
			this.toolBarButton10 = new System.WinForms.ToolBarButton ();
			this.m_menuMRUSep = new System.WinForms.MenuItem ();
			this.toolBarButton8 = new System.WinForms.ToolBarButton ();
			this.menuItem8 = new System.WinForms.MenuItem ();
			this.menuItem4 = new System.WinForms.MenuItem ();
			this.menuItem9 = new System.WinForms.MenuItem ();
			this.toolBarButton9 = new System.WinForms.ToolBarButton ();
			this.menuItem10 = new System.WinForms.MenuItem ();
			this.menuItem11 = new System.WinForms.MenuItem ();
			this.statusBarPanel1 = new System.WinForms.StatusBarPanel ();
			this.statusBarPanel2 = new System.WinForms.StatusBarPanel ();
			this.m_imageListTreeView = new System.WinForms.ImageList ();
			this.menuItem5 = new System.WinForms.MenuItem ();
			this.m_statusBar = new System.WinForms.StatusBar ();
			this.m_imageListToolBar = new System.WinForms.ImageList ();
			this.toolBarButton3 = new System.WinForms.ToolBarButton ();
			this.menuItem13 = new System.WinForms.MenuItem ();
			this.toolBarButton2 = new System.WinForms.ToolBarButton ();
			this.menuItem2 = new System.WinForms.MenuItem ();
			this.m_mainMenu = new System.WinForms.MainMenu ();
			this.menuItem3 = new System.WinForms.MenuItem ();
			this.m_lvFileView = new System.WinForms.ListView ();
			this.menuItem1 = new System.WinForms.MenuItem ();
			statusBarPanel3.BeginInit ();
			statusBarPanel1.BeginInit ();
			statusBarPanel2.BeginInit ();
			//@this.TrayHeight = 90;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			menuItem18.Text = "-";
			menuItem18.Index = 4;
			m_labelListView.Location = new System.Drawing.Point (259, 38);
			m_labelListView.Size = new System.Drawing.Size (438, 18);
			m_labelListView.BorderStyle = System.WinForms.BorderStyle.Fixed3D;
			m_toolTip.SetToolTip (m_labelListView, "Shows Folder(s),File(s) and Total Size in bytes under current working folder");
			m_labelListView.TabIndex = 5;
			menuItem15.Text = "&Refresh";
			menuItem15.Index = 2;
			menuItem15.Click += new System.EventHandler (this.OnClickRefresh);
			groupBox1.Location = new System.Drawing.Point (2, 32);
			groupBox1.TabIndex = 6;
			groupBox1.TabStop = false;
			groupBox1.Size = new System.Drawing.Size (702, 4);
			menuItem14.Text = "&File";
			menuItem14.Index = 1;
			menuItem14.MenuItems.All = new System.WinForms.MenuItem[3] {this.menuItem5, this.menuItem11, this.menuItem15};
			m_toolBar.ImageList = this.m_imageListToolBar;
			m_toolBar.Size = new System.Drawing.Size (702, 32);
			m_toolBar.ButtonSize = new System.Drawing.Size (25, 25);
			m_toolBar.DropDownArrows = true;
			m_toolBar.Appearance = System.WinForms.ToolBarAppearance.Flat;
			m_toolBar.TabIndex = 0;
			m_toolBar.ShowToolTips = true;
			m_toolBar.ButtonClick += new System.WinForms.ToolBarButtonClickEventHandler (this.OnClickToolBar);
			m_toolBar.Buttons.All = new System.WinForms.ToolBarButton[12] {this.toolBarButton1, this.toolBarButton2, this.toolBarButton12, this.toolBarButton6, this.toolBarButton3, this.toolBarButton4, this.toolBarButton11, this.toolBarButton8, this.toolBarButton9, this.toolBarButton10, this.toolBarButton7, this.toolBarButton5};
			toolBarButton12.ImageIndex = 2;
			toolBarButton12.ToolTipText = "Configure Server and Client Properties";
			toolBarButton11.ImageIndex = 5;
			toolBarButton11.ToolTipText = "Refresh Folder and File Views at Root Level";
			//@m_toolTip.SetLocation (new System.Drawing.Point (632, 7));
			m_toolTip.Active = true;
			m_menuMRU2.Visible = false;
			m_menuMRU2.Text = "MRU2";
			m_menuMRU2.Index = 6;
			m_menuMRU2.Click += new System.EventHandler (this.OnClickMenuMRU2);
			m_labelTreeView.Location = new System.Drawing.Point (8, 38);
			m_labelTreeView.Size = new System.Drawing.Size (246, 18);
			m_labelTreeView.BorderStyle = System.WinForms.BorderStyle.Fixed3D;
			m_toolTip.SetToolTip (m_labelTreeView, "Shows current working directory on FTP server");
			m_labelTreeView.TabIndex = 4;
			m_menuMRU1.Visible = false;
			m_menuMRU1.Text = "MRU1";
			m_menuMRU1.Index = 5;
			m_menuMRU1.Click += new System.EventHandler (this.OnClickMenuMRU1);
			toolBarButton7.Style = System.WinForms.ToolBarButtonStyle.Separator;
			toolBarButton4.ImageIndex = 4;
			toolBarButton4.ToolTipText = "Download file from FTP server";
			toolBarButton6.Style = System.WinForms.ToolBarButtonStyle.Separator;
			menuItem16.Text = "&Configure";
			menuItem16.Index = 3;
			menuItem16.Click += new System.EventHandler (this.OnClickConfigure);
			toolBarButton1.ImageIndex = 0;
			toolBarButton1.ToolTipText = "Connect to FTP Server";
			toolBarButton5.ImageIndex = 8;
			toolBarButton5.ToolTipText = "Close FTP Explorer";
			m_menuMRU3.Visible = false;
			m_menuMRU3.Text = "MRU3";
			m_menuMRU3.Index = 7;
			m_menuMRU3.Click += new System.EventHandler (this.OnClickMenuMRU3);
			m_progressBarFileStatus.Visible = false;
			m_toolTip.SetToolTip (m_progressBarFileStatus, "Shows file transfer progress");
			m_progressBarFileStatus.Location = new System.Drawing.Point (507, 446);
			m_progressBarFileStatus.TabIndex = 7;
			m_progressBarFileStatus.Size = new System.Drawing.Size (195, 18);
			m_progressBarFileStatus.Step = 2;
			m_tvFolderView.ImageList = this.m_imageListTreeView;
			m_tvFolderView.Location = new System.Drawing.Point (6, 61);
			m_tvFolderView.Size = new System.Drawing.Size (248, 382);
			m_toolTip.SetToolTip (m_tvFolderView, "Shows accessible folder(s) on the FTP Server");
			m_tvFolderView.TabIndex = 1;
			m_tvFolderView.AfterSelect += new System.WinForms.TreeViewEventHandler (this.OnAfterSelectFolderView);
			m_menuMRU4.Visible = false;
			m_menuMRU4.Text = "MRU4";
			m_menuMRU4.Index = 8;
			m_menuMRU4.Click += new System.EventHandler (this.OnClickMenuMRU4);
			//@statusBarPanel3.SetLocation (new System.Drawing.Point (7, 34));
			statusBarPanel3.ToolTipText = "Displays Local working directory";
			statusBarPanel3.Width = 200;
			toolBarButton10.ImageIndex = 7;
			toolBarButton10.ToolTipText = "About FTP Explorer";
			m_menuMRUSep.Visible = false;
			m_menuMRUSep.Text = "-";
			m_menuMRUSep.Index = 9;
			toolBarButton8.Style = System.WinForms.ToolBarButtonStyle.Separator;
			menuItem8.Text = "&Help";
			menuItem8.Index = 2;
			menuItem8.MenuItems.All = new System.WinForms.MenuItem[2] {this.menuItem9, this.menuItem10};
			menuItem4.Text = "-";
			menuItem4.Index = 2;
			menuItem9.Text = "&System Info";
			menuItem9.Index = 0;
			menuItem9.Click += new System.EventHandler (this.OnClickSystemInfo);
			toolBarButton9.ImageIndex = 6;
			toolBarButton9.ToolTipText = "Displays System Information";
			menuItem10.Text = "&About";
			menuItem10.Index = 1;
			menuItem10.Click += new System.EventHandler (this.OnClickAbout);
			menuItem11.Text = "&Download";
			menuItem11.Index = 1;
			menuItem11.Click += new System.EventHandler (this.OnClickDownloadFile);
			//@statusBarPanel1.SetLocation (new System.Drawing.Point (112, 7));
			statusBarPanel1.ToolTipText = "Displays connection status";
			statusBarPanel1.Width = 255;
			//@statusBarPanel2.SetLocation (new System.Drawing.Point (230, 7));
			statusBarPanel2.ToolTipText = "Displays progress status of FTP connection";
			statusBarPanel2.Width = 250;
			//@m_imageListTreeView.SetLocation (new System.Drawing.Point (486, 7));
			m_imageListTreeView.ImageSize = new System.Drawing.Size (16, 16);
			m_imageListTreeView.ImageStream = (System.WinForms.ImageListStreamer) resources.GetObject ("m_imageListTreeView.ImageStream");
			m_imageListTreeView.ColorDepth = System.WinForms.ColorDepth.Depth8Bit;
			m_imageListTreeView.TransparentColor = System.Drawing.Color.Transparent;
			menuItem5.Text = "&Upload";
			menuItem5.Index = 0;
			menuItem5.Click += new System.EventHandler (this.OnClickUploadFile);
			m_statusBar.BackColor = System.Drawing.SystemColors.Control;
			m_statusBar.SizingGrip = false;
			m_statusBar.Location = new System.Drawing.Point (0, 444);
			m_statusBar.Size = new System.Drawing.Size (702, 20);
			m_statusBar.TabIndex = 3;
			m_statusBar.ShowPanels = true;
			m_statusBar.Panels.All = new System.WinForms.StatusBarPanel[3] {this.statusBarPanel1, this.statusBarPanel2, this.statusBarPanel3};
			//@m_imageListToolBar.SetLocation (new System.Drawing.Point (348, 7));
			m_imageListToolBar.ImageSize = new System.Drawing.Size (22, 22);
			m_imageListToolBar.ImageStream = (System.WinForms.ImageListStreamer) resources.GetObject ("m_imageListToolBar.ImageStream");
			m_imageListToolBar.ColorDepth = System.WinForms.ColorDepth.Depth8Bit;
			m_imageListToolBar.TransparentColor = System.Drawing.Color.Transparent;
			toolBarButton3.ImageIndex = 3;
			toolBarButton3.ToolTipText = "Upload File to FTP server";
			menuItem13.Text = "&Exit";
			menuItem13.Index = 10;
			menuItem13.Click += new System.EventHandler (this.OnClickExit);
			toolBarButton2.ImageIndex = 1;
			toolBarButton2.ToolTipText = "Disconnect current session";
			menuItem2.Text = "&Connect";
			menuItem2.Index = 0;
			menuItem2.Click += new System.EventHandler (this.OnClickConnect);
			//@m_mainMenu.SetLocation (new System.Drawing.Point (7, 7));
			m_mainMenu.MenuItems.All = new System.WinForms.MenuItem[3] {this.menuItem1, this.menuItem14, this.menuItem8};
			menuItem3.Text = "&Disconnect";
			menuItem3.Index = 1;
			menuItem3.Click += new System.EventHandler (this.OnClickDisconnect);
			m_lvFileView.Location = new System.Drawing.Point (258, 61);
			m_lvFileView.Size = new System.Drawing.Size (439, 382);
			m_lvFileView.FullRowSelect = true;
			m_lvFileView.View = System.WinForms.View.Report;
			m_lvFileView.ForeColor = System.Drawing.SystemColors.WindowText;
			m_toolTip.SetToolTip (m_lvFileView, "Shows File(s) on the selected folder");
			m_lvFileView.TabIndex = 2;
			menuItem1.Text = "&Server";
			menuItem1.Index = 0;
			menuItem1.MenuItems.All = new System.WinForms.MenuItem[11] {this.menuItem2, this.menuItem3, this.menuItem4, this.menuItem16, this.menuItem18, this.m_menuMRU1, this.m_menuMRU2, this.m_menuMRU3, this.m_menuMRU4, this.m_menuMRUSep, this.menuItem13};
			this.Text = "FTP Explorer Beta 1";
			this.MaximizeBox = false;
			this.StartPosition = System.WinForms.FormStartPosition.CenterScreen;
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.BorderStyle = System.WinForms.FormBorderStyle.FixedDialog;
			this.Icon = (System.Drawing.Icon) resources.GetObject ("$this.Icon");
			this.Menu = this.m_mainMenu;
			this.ClientSize = new System.Drawing.Size (702, 464);
			this.Controls.Add (this.m_progressBarFileStatus);
			this.Controls.Add (this.groupBox1);
			this.Controls.Add (this.m_labelListView);
			this.Controls.Add (this.m_labelTreeView);
			this.Controls.Add (this.m_statusBar);
			this.Controls.Add (this.m_lvFileView);
			this.Controls.Add (this.m_tvFolderView);
			this.Controls.Add (this.m_toolBar);
			statusBarPanel3.EndInit ();
			statusBarPanel1.EndInit ();
			statusBarPanel2.EndInit ();
		}

		protected void OnClickMenuMRU4 (object sender, System.EventArgs e)
		{
			string l_strFTPServer = m_arrMRUConn[3].FTPServer ;
			string l_strFTPUser = m_arrMRUConn[3].FTPUser;
			ConnectToFTPServer(l_strFTPServer,l_strFTPUser);
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -