|
|
Code Samples
The product includes numerous VB.NET, C# and ASP.NET sample applications.
All samples include complete source code.
For more detailed sample code please refer to the sample applications.
Downloading a File
Listing 1 demonstrates using the Download static method
of the FtpClient class.
You can connect, download and disconnect in a single method call.
Alternatively, you can connect and perform multiple operations using
the instance methods before disconnecting.
FtpClient.Download("ftp.microsoft.com", _
"anonymous", _
"me@mycompany.com", _
TransferMode.Binary, _
"/Services/Museum/pictures/ballmerplunge.jpg", _
"c:\temp\ballmerplunge.jpg")
|
Listing 1 Using the Download static method of the FtpClient class
Uploading a File
Listing 2 demonstrates using the Upload static method
of the FtpClient class.
You can connect, upload and disconnect in a single method call.
Alternatively, you can connect and perform multiple operations using
the instance methods before disconnecting.
FtpClient.Upload("ftp.microsoft.com", _
"sballmer", _
"topsecret", _
TransferMode.Binary, _
"c:\temp\ballmerplunge.jpg", _
"/Services/Museum/pictures/ballmerplunge.jpg")
|
Listing 2 Using the Upload static method of the FtpClient class
Listing a Directory's Contents
Listing 3 lists a remote directory's contents and parses
the returned text to make processing easier.
Dim ftpClient as New FtpClient()
Dim listLines() as String
Dim directoryListItems() As DirectoryListItem
ftpClient.Connect("ftp.microsoft.com", "anonymous", "me@mycompany.com")
' Get directory listing as a string array
listLines = ftpClient.RemoteDirectory.List("/Services/Museum/pictures")
' Parse directory listing lines and sort into alphabetic order
directoryListItems = DirectoryListParser.ParseDirectoryList(listLines)
DirectoryListItem.Sort(directoryListItems)
' Process directory list items
ftpClient.Disconnect()
|
Listing 3 Listing a Directory's Contents
|