Introduced
Microsoft's. NET Framework 2.0 has increased support for FTP relative to 1.x. In the past, in order to meet my needs, I did not use a Third-party class library to achieve FTP functionality, but for the sake of reliability, it is better to use the. NET Framework analogy. My Code does not form a reusable class library, but it is easier to understand and meets your needs. It can upload, download, delete and other arbitrary functions. At the end of this article we will show you the simple code for FTP under. NET 2.0, which is in C #. Perhaps because this is the. NET new class, or the third party class library has been able to achieve your needs, the. NET 2.0 of this part of the class library has not received enough attention.
Background
As part of my work, I have used the FTP module, but I can only use it in. NET 1.1, so I can't delve into the implementation of. NET 2.0 FTP. But I believe that the support for FTP under NE 2.0 is very good.
Code
Don't forget to introduce namespaces
Using System.Net;
Using System.IO;
The following steps include a general procedure for using the FtpWebRequest class to implement FTP functionality
1, create a FtpWebRequest object, point to the FTP server URI
2, set the FTP implementation method (upload, download, etc.)
3. Set properties for FtpWebRequest objects (whether SSL is supported, binary transmissions are used, etc.)
4, Set login authentication (username, password)
5, the implementation of the request
6, receive the corresponding flow (if necessary)
7, if there is no open stream, then close the FTP request
The development of any FTP application requires a related FTP server and its configuration information. FtpWebRequest exposes some properties to set this information.
The next code example is the upload function
First, set a URI address, including the path and file name. This URI is used in the FtpWebRequest instance.