示例#1
0
        private void ConnectBtn_Click(object sender, EventArgs e)
        {
            myFTP        = new MyFTP();
            myFTP.Server = ServerBox.Text.Trim();
            if (myFTP.Server.Length == 0)
            {
                ServerWarning.Visible = true;
                ServerBox.Focus();
                return;
            }
            ServerWarning.Visible = false;
            myFTP.UserName        = UserNameBox.Text.Trim();
            if (myFTP.UserName.Length == 0)
            {
                UserWarning.Visible = true;
                UserNameBox.Focus();
                return;
            }
            UserWarning.Visible = false;
            myFTP.Password      = PwdBox.Text.Trim();
            try { myFTP.Port = int.Parse(PortBox.Text); }catch { PortWarning.Visible = true; PortBoxLabel.Focus(); return; }
            PortWarning.Visible = false;

            RemoteTree.Nodes.Clear();
            AddLog($"正在尝试连接 {myFTP.Server}:{myFTP.Port}......");
            try { myFTP.Connect(); } catch (Exception ex) { AddLog("错误: " + ex.Message, 1); return; }
            AddLog($"FTP已连接到 {myFTP.Server}:{myFTP.Port}, 成功登录!");
            Text = $"极简FTP [{myFTP.Server}:{myFTP.Port}]";
            PreLoadRemoteTree();
        }
示例#2
0
        private void ReloadRemoteNode(TreeNode node)
        {
            AddLog($"正在获取{node.Name}的目录列表......");
            if (myFTP.Connected() == false)
            {
                myFTP.Connect();
            }
            node.Nodes.Clear();
            int              sz   = 0;
            string           path = node.Name;
            List <MyFTPItem> list = new List <MyFTPItem>();

            try
            {
                myFTP.ChangeDir(node.Name);
                list = myFTP.GetFileList();
            }
            catch (Exception ex)
            {
                AddLog(ex.Message, 1);
                return;
            }
            foreach (MyFTPItem item in list)
            {
                TreeNode sonNode = new TreeNode(item.Name);
                sonNode.Name = node.Name + item.Name;               //完整目录
                sonNode.Tag  = sonNode.Name;
                if (item.Type == "dir")
                {
                    sonNode.Name               = sonNode.Name + "/";
                    sonNode.ImageIndex         = ImageIndex.FolderClose; //获取节点显示图片
                    sonNode.SelectedImageIndex = ImageIndex.FolderOpen;  //选择节点显示图片
                    sonNode.Nodes.Add("");
                }
                else
                {
                    sonNode.ImageIndex         = ImageIndex.File; //获取节点显示图片
                    sonNode.SelectedImageIndex = ImageIndex.File; //选择节点显示图片
                }

                node.Nodes.Add(sonNode);
                sz += 1;
            }
            AddLog($"获取成功!共获取{sz}项。");
        }