Export (0) Print
Expand All

FtpWebRequest.UsePassive Property

Gets or sets the behavior of a client application's data transfer process.

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

public function get UsePassive () : boolean 
public function set UsePassive (value : boolean)

Property Value

Type: System.Boolean
false if the client application's data transfer process listens for a connection on the data port; otherwise, true if the client should initiate a connection on the data port. The default value is true.

ExceptionCondition
InvalidOperationException

A new value was specified for this property for a request that is already in progress.

Setting the UsePassive property to true sends the "PASV" command to the server. This command requests the server to listen on a data port and to wait for a connection rather than initiate one upon receipt of a transfer command.

For a description of the behaviors that are specified using UsePassive, see RFC 959, "File Transfer Protocol," Section 3.2, "Establishing Data Connections" and Section 4.1.2, "Transfer Parameter Commands," available at http://www.rfc-editor.org/.

Changing UsePassive after calling the GetRequestStream, BeginGetRequestStream, GetResponse, or BeginGetResponse method causes an InvalidOperationException exception.

If UsePassive is set to true, the FTP server may not send the size of the file, and download progress can always be zero. If UsePassive is set to false, a firewall can raise an alert and block the file download.

The following code example retrieves and displays property values for a specified FtpWebRequest object.

No code example is currently available or this language may not be supported.
    // DisplayRequestProperties prints a request's properties.
    // This method should be called after the request is sent to the server.

private:
    static void DisplayRequestProperties(FtpWebRequest* request)
    {
        Console::WriteLine(S"User {0} {1}", 
            request->Credentials->GetCredential(request->RequestUri,S"basic")->UserName,
            request->RequestUri
            );
        Console::WriteLine(S"Request: {0} {1}", 
            request->Method,
            request->RequestUri
            );
        Console::WriteLine(S"Passive: {0}  Keep alive: {1}  Binary: {2} Timeout: {3}.", __box(request->Passive), __box(request->KeepAlive), __box(request->Binary),
            request->Timeout == -1 ? S"none" : request->Timeout.ToString()
            );
        IWebProxy* proxy = request->Proxy;
	 if (proxy)
	 {
        	Console::WriteLine(S"Proxy: {0}",
            		proxy->GetProxy(request->RequestUri));
	 }
	 else
	 {
		  Console::WriteLine(S"Proxy: (none)");

	 }		       
	 Console::WriteLine(S"ConnectionGroup: {0}",
            request->ConnectionGroupName == 0 ? S"none" : request->ConnectionGroupName
            );
        Console::WriteLine(S"Encrypted connection: {0}", 
               __box(request->EnableSsl));
    }

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft