TreeView1 is a. Net treeview control. Please add a control to the WinForm interface
Dec in Form1_Load is an object that instantiates Ftpclient.vb, Ftpdetails is used to store FTP logon credentials.
Form1.vb
1Public Class form1class Form1
2
3 Dim ftp as FtpClient
4 Dim localfilelist as New DataTable
5
6 Private Sub Form1_Load () Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Myba Se. Load
7 Dim Dec as New ftpclient.ftpdetails ("www.cnblogs.com", "Cnblogvip", "**********")
8 ftp = New ftpclient (DEC)
9 Loadftptree (Treeview1.nodes, "") calls this code to mount the remote FTP structure tree
10
End Sub
12
13 ' This method is used to obtain remote directory and file tree
Private Sub loadftptree () Sub Loadftptree (ByVal Nodes as TreeNodeCollection, ByVal Path as String)
15 ' access to all levels of classification
Dim Snode as Integer =-1
17 ' Gets the current directory list via FTP
Dim result as String = Ftp.getfilelist (Path)
Dim files () as String = Split (result, vbCrLf) ' separates the text returned by the FTP server from the directory or file, file or directory name, file size
Dim ffi as New ftpclient.ftplistfileinfo
If files. Length > 0 Then
22 ' Load node
Dim I as Integer
for I = 0 to files. Length-2
FFI. Parserstring (Files (I)) ' splits the returned line. Isolate the directory or file, file or directory name, file size
If FFI. Isdirectory = True and FFI. FileName <> "..." and FFI. FileName <> "." Then ' If the directory is valid.
Snode + 1
nodes.add (0, Ffi. FileName) ' Because it is a directory, the previous arguments are saved similarly. The same function as tag, where the size of the file is saved
Dim NewPath as String = Path + "/" + FFI. FileName ' filename ' If the file represents the filename, the directory name
application.doevents ()
31 ' reads the child node of the current node load ()
Loadftptree (Nodes (Snode). Nodes, NewPath) ' recursively checks if there are subdirectories under the current directory
ElseIf FFI. isdirectory = False Then ' If it is a file
Snode + 1
Nodes.Add (FFI. Filesize.tostring, Ffi. FileName) ' Add to the node
End If
Notoginseng Next
End If
Treeview1.expandall ()
End Sub