Hands-On Network Programming with C# and .NET Core
上QQ阅读APP看书,第一时间看更新

FtpWebRequest

The FtpWebRequest class provides many of the same properties as the HttpWebRequest class. The distinction comes in the form of a few specific properties for configuring reliable behavior when processing potentially large files over a potentially unreliable or slow connection. To that end, it provides the ReadWriteTimeout property that specifies the maximum amount of time allowed for processing the file stream. There's also the FTP-specific UsePassive property that allows a user to specify the use of the passive transfer process, leaving an open listening connection on the server for clients to access files accordingly.

There's also the explicit EnableSsl parameter, which you might have noticed was not a property of HttpWebRequest. Interestingly, this is necessary for the FtpWebRequest class but not the HttpWebRequest class because the use of Secure Sockets Layer (SSL) in HTTP is actually specified in the protocol component of the URI (that is, HTTP versus HTTPS); whereas with FTP, that feature must be enabled explicitly.

Once again, the actual use of the FtpWebRequest class is exactly the same as with the WebRequest base class. Once the protocol-specific settings are properly configured through the class properties, FTP is ultimately just another request/response protocol for accessing remote resources.