Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I need to view files and folders which is available in remote system directory using FTP connection. I established a connction to the remote system usign FTP. but i dont know how to view the files and folders as a tree structure format. that tree structure like.
-root directory
+sub directory
- subdirectory
-file
-file

if any one know the possible solutions please do let me know..

thanks,


regards
sasi
Posted
Updated 22-Jul-11 2:09am
v2
Comments
Herman<T>.Instance 22-Jul-11 10:03am    
see http://msdn.microsoft.com/en-us/library/ms229716.aspx

1 solution

You need to use the class System.Net.FtpWebRequest. Some code samples are shown on the MSDN help page for this class: http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx[^].

The code shows some FTP request methods represented by the class System.Net.WebRequestMethods.Ftp, see http://msdn.microsoft.com/en-us/library/system.net.webrequestmethods.ftp.aspx[^]. To represent the FTP file structure as a tree, you well need some other methods, first of all System.Net.WebRequestMethods.Ftp.ListDirectory or System.Net.WebRequestMethods.Ftp.ListDirectoryDetails.

Look some code samples and discussion here: http://stackoverflow.com/questions/3298922/how-to-list-directory-contents-with-ftp-in-c[^].

All you need to do is to walk throw all the sub-directories recursively and build a tree. I would not recommend doing it at all as it may take too much time. It would be much better to show a one-level list of file and sub-directories of one directory at a time as Windows Explorer does in its Detail or List view. Other sub-directories would be shown on demand on Enter or click.

At least make sure you use separate thread to work with FTP, communicate with UI using the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading with UI:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900