FtpWebRequest.GetResponse Method

Returns the FTP server response.

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

public override WebResponse GetResponse ()
public WebResponse GetResponse ()
public override function GetResponse () : WebResponse
Not applicable.

Return Value

A WebResponse reference that contains an FtpWebResponse instance. This object contains the FTP server's response to the request.

Exception typeCondition


GetResponse or BeginGetResponse has already been called for this instance.

- or -

An HTTP proxy is enabled, and you attempted to use an FTP command other than WebRequestMethods.Ftp.DownloadFile, WebRequestMethods.Ftp.ListDirectory, or WebRequestMethods.Ftp.ListDirectoryDetails.


EnableSsl is set to true, but the server does not support this feature.

To access the FTP-specific properties, you must cast the WebResponse object returned by this method to FtpWebResponse.

GetResponse causes a control connection to be established, and might also create a data connection. GetResponse blocks until the response is received. To prevent this, you can perform this operation asynchronously by calling the BeginGetResponse and EndGetResponse methods in place of GetResponse.

If the Proxy property is set, either directly or in a configuration file, communications with the FTP server are made through the proxy.

If a WebException is thrown, use the Response and Status properties of the exception to determine the response from the server.

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.


Multiple calls to GetResponse return the same response object; the request is not reissued.

Notes to Callers: This method generates network traffic.

The following code example demonstrates copying a file to a request's data stream and sending a request to append data to a file to the server. The example calls GetResponse to send the request and block until the response is returned by the server.

public static bool AppendFileOnServer(string fileName, Uri serverUri)
    // The URI described by serverUri should use the ftp:// scheme.
    // It contains the name of the file on the server.
    // Example: ftp://contoso.com/someFile.txt. 
    // The fileName parameter identifies the file containing 
    // the data to be appended to the file on the server.
    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.AppendFile;
    StreamReader sourceStream = new StreamReader(fileName);
    byte [] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
    request.ContentLength = fileContents.Length;
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");
    Stream requestStream = request.GetRequestStream();
    requestStream.Write(fileContents, 0, fileContents.Length);
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();
    Console.WriteLine("Append status: {0}",response.StatusDescription);
    return true;

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0