Using FtpWebRequest and FtpWebResponse classes using VB.NET in .NET Framework 2.0
In this article I’ll try to explain how you can use the newly added classes FtpWebRequest and FtpWebResponse to interact with any FTP server
In the new .NET Framework 2.0 Microsoft has added classes for operating with FTP servers. These classes are added in the System.Net namespace. You can download files from a remote FTP server using WebClient class. In this article I’ll explain how you can use these classes to get the list of directories and files present on a FTP server.
First you need to create an instance of the FtpWebRequest class and set the ftp address of the folder you want to get list from.
Then you need to set the user name and password for accessing the FTP server. There is a property called Credentials in the FtpWebRequest class that is of type ICredential and you can set it to an object of type NetworkCredential object like this.
Then you need to specify the Method of this class which is an instance of WebRequestMethods object like this.
After specifying these properties I’ll retrieve the list of files and folders using a Stream reader and display that in the console. The code for this is as follows.
This will be the simplest example of using these classes to work with the file transfer protocol. Try to work with the code, change it and see what happens. Also find about all the members of this class from the MSDN library.