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