Export (0) Print
Expand All

FtpWebResponse Class

Note: This class is new in the .NET Framework version 2.0.

Encapsulates a File Transfer Protocol (FTP) server's response to a request.

Namespace: System.Net
Assembly: System (in system.dll)

public class FtpWebResponse : WebResponse, IDisposable
public class FtpWebResponse extends WebResponse implements IDisposable
public class FtpWebResponse extends WebResponse implements IDisposable

Instances of FtpWebResponse are obtained by calling the GetResponse method. The returned object must be cast to an FtpWebResponse. When your application no longer needs the FtpWebResponse object, call the Close method to free the resources held by the FtpWebResponse.

The StatusCode property contains the status code returned by the server, and the StatusDescription property returns the status code and a message that describes the status. The values returned by these properties change as the messages are returned by the server.

Any data returned by the request, such as the list of file names returned for a ListDirectory request, is available in the stream returned by the GetResponseStream method. The length of the stream data can be obtained from the ContentLength property.

The following code example sends a request to delete a file on an FTP server and displays the status message from the server's response to the request. For additional examples, see the members of the WebRequestMethods.Ftp and FtpWebRequest classes.

public static bool DeleteFileOnServer(Uri serverUri)
{
    // 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;
}

System.Object
   System.MarshalByRefObject
     System.Net.WebResponse
      System.Net.FtpWebResponse

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft