RSS Forums RSS

FTP Server Directory Treeview

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Reply
Posts: 117
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 6
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

FTP Server Directory Treeview

  #1  
Jan 9th, 2009
Just because there is no help for this online that i could find, I'm posting this for all the other coders...

This makes use of a third part class downloaded from code project... AWESOME FTP class this , i owe the creators a huge thank you ...

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Windows.Forms;
using System.IO;
using System.Net.Mail;
using System.Net;
using System.Net.Mime;
using System.Web;
using System.IO.Compression;
using Microsoft.Win32;
using System.Net.Sockets;
using System.Runtime;


namespace TestDummyTWO
{
    public partial class Form1 : Form
    {
        FTPLib.FTP FTPLIB = new FTPLib.FTP();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            /* THIS IS THE FORMULA
             * TreeNode MyNodeMain = new TreeNode();
             * TreeNode MyNodeChild = new TreeNode();
             * MyNodeMain.Text = "Main";
             * MyNodeChild.Text = "child";
             
             * mytree.Nodes.Add(MyNodeMain);
             * MyNodeMain.Nodes.Add(MyNodeChild);
            */

           

            FTPLIB.server = "******";
            FTPLIB.user = "*******";
            FTPLIB.pass = "******";

            foreach (string S in FTPLIB.ListDirectories())
            {
                /*          Making parent node          */
                TreeNode ParentNode = new TreeNode();
                ParentNode.Text = S.Substring(55);
                treeView1.Nodes.Add(ParentNode);

                /*          Making child node           */

                FTPLIB.ChangeDir("//" + S.Substring(55) + "/");
                foreach (string S2 in FTPLIB.List())
                {
                    FTPLIB.ChangeDir("//" + S.Substring(55) + "/");

                    TreeNode ChildNode = new TreeNode();
                    ChildNode.Text = S2.Substring(55);
                    ParentNode.Nodes.Add(ChildNode);

                    FTPLIB.ChangeDir(".");
                }

            }
        }
    }
}

Happy coding people , code is shibby ....
Last edited by cVz : Jan 9th, 2009 at 8:38 am.
Delphi & C# programmer deluxe...
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,734
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 184
LizR LizR is offline Offline
Posting Virtuoso

Re: FTP Server Directory Treeview

  #2  
Jan 9th, 2009
lets pray the ftp servers you use always return exactly the same format in each line then, and that they dont have longer filenames, or usernames or longer/shorter permissions.

However, builing a tree view of something is generally an easy enough concept, and your treeview only allows 1 level, its not recursive.. but, its good you got there in the end.

Btw, shouldnt
FTPLIB.ChangeDir(".");
be a little pointless as you are changing to a fully qualified path each time. and "." means dont change.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Posts: 117
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 6
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: FTP Server Directory Treeview

  #3  
Jan 9th, 2009
FTPLIB.ChangeDir(".");

Takes you to the root folder again, this is just an example , i mean surely every person has a brain to take this code and play around with it ... i just wanted to help man ... seriously....

Its the theory you see there, i just gave an example , one can use this in small applications ... (i hate the treeview though, might do it with a listview....) but we already played with that hehehe

Thanks for all your help man , I'm finally finding some structure in my application to work with ...
Delphi & C# programmer deluxe...
Reply With Quote  
Posts: 117
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 6
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: FTP Server Directory Treeview

  #4  
Jan 9th, 2009
I guess you could just use
FTPLIB.ChangeDir("//");
or something, on my server the previous folder is the "."-dir so going there takes you back back back ... cool navigation i tell you ...
Last edited by cVz : Jan 9th, 2009 at 9:32 am.
Delphi & C# programmer deluxe...
Reply With Quote  
Posts: 1,734
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 184
LizR LizR is offline Offline
Posting Virtuoso

Re: FTP Server Directory Treeview

  #5  
Jan 9th, 2009
Thats very unusual. On every other OS in the world, "." is current folder, including windows and unix.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C# Forum
Views: 905 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:58 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC