Implements a File Transfer Protocol (FTP) client.
| C# | Visual Basic |
public class FtpWebRequest : WebRequest
Public Class FtpWebRequest _ Inherits WebRequest
| All Members | Methods | Properties | |||
| Icon | Member | Description |
|---|---|---|
| Abort()()() | Aborts the Request (Inherited from WebRequest.) | |
| BeginGetRequestStream(AsyncCallback, Object) | When overridden in a descendant class, provides an asynchronous version of the GetRequestStream()()() method. (Inherited from WebRequest.) | |
| BeginGetResponse(AsyncCallback, Object) | When overridden in a descendant class, begins an asynchronous request for an Internet resource. (Inherited from WebRequest.) | |
| ConnectionGroupName | When overridden in a descendant class, gets or sets the name of the connection group for the request. (Inherited from WebRequest.) | |
| ContentLength |
This property supports the .NET Compact Framework infrastructure and is not intended to be used directly from your code.
Gets or sets a value that is ignored by the FtpWebRequest class.
(Overrides WebRequest.ContentLength.) | |
| ContentType |
This property supports the .NET Compact Framework infrastructure and is not intended to be used directly from your code.
Always throws a NotSupportedException.
(Overrides WebRequest.ContentType.) | |
| Credentials |
Gets or sets the credentials used to communicate with the FTP server.
(Overrides WebRequest.Credentials.) | |
| EndGetRequestStream(IAsyncResult) | When overridden in a descendant class, returns a Stream for writing data to the Internet resource. (Inherited from WebRequest.) | |
| EndGetResponse(IAsyncResult) | When overridden in a descendant class, returns a WebResponse. (Inherited from WebRequest.) | |
| Equals(Object) | (Inherited from Object.) | |
| Finalize()()() | Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) | |
| GetHashCode()()() | Serves as a hash function for a particular type. GetHashCode()()() is suitable for use in hashing algorithms and data structures like a hash table. (Inherited from Object.) | |
| GetRequestStream()()() |
Retrieves the stream used to upload data to an FTP server.
(Overrides WebRequest.GetRequestStream()()().) | |
| GetResponse()()() |
Returns the FTP server response.
(Overrides WebRequest.GetResponse()()().) | |
| GetType()()() | Gets the Type of the current instance. (Inherited from Object.) | |
| Headers |
This property supports the .NET Compact Framework infrastructure and is not intended to be used directly from your code.
Gets an empty WebHeaderCollection object.
(Overrides WebRequest.Headers.) | |
| MemberwiseClone()()() | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| Method |
Gets or sets the command to send to the FTP server.
(Overrides WebRequest.Method.) | |
| PreAuthenticate | When overridden in a descendant class, indicates whether to pre-authenticate the request. (Inherited from WebRequest.) | |
| Proxy | ||
| RegisterPrefix()()() |
Register this class with the WebRequest class.
| |
| RenameTo |
Gets or sets the new name of a file being renamed.
| |
| RequestUri |
Gets the URI requested by this instance.
(Overrides WebRequest.RequestUri.) | |
| Timeout | Gets or sets the length of time before the request times out. (Inherited from WebRequest.) | |
| ToString()()() | (Inherited from Object.) | |
| UseBinary |
Gets or sets a Boolean value that specifies the data type for file transfers.
| |
| UsePassive |
Gets or sets the behavior of a client application's data transfer process.
|
You must call the static method RegisterPrefix()()() before this class can be used with Create(String). You only need to call RegisterPrefix()()() once in your application.
To obtain an instance of FtpWebRequest, use the Create(String) method after calling RegisterPrefix()()(). You can also use the WebClient class to upload and download information from an FTP server. Using either of these approaches, when you specify a network resource that uses the FTP scheme (for example, "ftp://contoso.com") the FtpWebRequest class provides the ability to programmatically interact with FTP servers. The URI may be relative or absolute. If the URI is of the form "ftp://contoso.com/%2fpath" (%2f is an escaped '/'), then the URI is absolute, and the current directory is /path. If, however, the URI is of the form "ftp://contoso.com/path", first the .NET Framework logs into the FTP server (using the user name and password set by the Credentials property), then the current directory is set to <UserLoginDirectory>/path. You must have a valid user name and password for the server or the server must allow anonymous logon. You can specify the credentials used to connect to the server by setting the Credentials property or you can include them in the UserInfo portion of the URI passed to the Create(String) method. If you include UserInfo information in the URI, the Credentials property is set to a new network credential with the specified user name and password information.The following code example demonstrates deleting a file from an FTP server.
CopyC#
public static bool DeleteFileOnServer(Uri serverUri) { FtpWebRequest.RegisterPrefix(); // The serverUri parameter should use the ftp:// scheme. // It contains the name of the server file that is to be deleted. // Example: ftp://contoso.com/someFile.txt. // if (serverUri.Scheme != Uri.UriSchemeFtp) { return false; } // Get the object used to communicate with the server. FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); request.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse) request.GetResponse(); Console.WriteLine("Delete status: {0}",response.StatusDescription); response.Close(); return true; }
The following code example demonstrates downloading a file from an FTP server by using the WebClient class.
CopyC#
public static bool DisplayFileFromServer(Uri serverUri) { // The serverUri parameter should start with the ftp:// scheme. if (serverUri.Scheme != Uri.UriSchemeFtp) { return false; } // Get the object used to communicate with the server. WebClient request = new WebClient(); // This example assumes the FTP site uses anonymous logon. request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com"); try { byte [] newFileData = request.DownloadData(serverUri.ToString()); string fileString = System.Text.Encoding.UTF8.GetString(newFileData); Console.WriteLine(fileString); } catch (WebException e) { Console.WriteLine(e.ToString()); } return true; }
| Object | |||
| MarshalByRefObject | |||
| WebRequest | |||
| FtpWebRequest | |||
[!:System.Net.FtpWebRequest]