Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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);
            }
        }