FtpWebRequest.UsePassive 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定用戶端應用程式之資料傳輸處理序的行為。
public:
property bool UsePassive { bool get(); void set(bool value); };
public bool UsePassive { get; set; }
member this.UsePassive : bool with get, set
Public Property UsePassive As Boolean
屬性值
如果用戶端應用程式的資料傳輸處理序會接聽資料連接埠上的連接,則為 false
;如果用戶端應該在資料連接埠上啟始連接,則為 true
。 預設值是 true
。
例外狀況
由於已經在進行的要求,已為這個屬性指定新的值。
範例
下列程式代碼範例會擷取並顯示指定 FtpWebRequest 物件的屬性值。
private:
// DisplayRequestProperties prints a request's properties.
// This method should be called after the request is sent to the server.
static void DisplayRequestProperties( FtpWebRequest^ request )
{
Console::WriteLine( "User {0} {1}", request->Credentials->GetCredential( request->RequestUri, "basic" )->UserName, request->RequestUri );
Console::WriteLine( "Request: {0} {1}", request->Method, request->RequestUri );
Console::WriteLine( "Passive: {0} Keep alive: {1} Binary: {2} Timeout: {3}.", request->UsePassive, request->KeepAlive, request->UseBinary, request->Timeout == -1 ? "none" : request->Timeout.ToString() );
IWebProxy^ proxy = request->Proxy;
if ( proxy )
{
Console::WriteLine( "Proxy: {0}", proxy->GetProxy( request->RequestUri ) );
}
else
{
Console::WriteLine( "Proxy: (none)" );
}
Console::WriteLine( "ConnectionGroup: {0}", request->ConnectionGroupName == nullptr ? "none" : request->ConnectionGroupName );
Console::WriteLine( "Encrypted connection: {0}", request->EnableSsl );
Console::WriteLine("Method: {0}", request->Method);
}
// 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("User {0} {1}",
request.Credentials.GetCredential(request.RequestUri,"basic").UserName,
request.RequestUri
);
Console.WriteLine("Request: {0} {1}",
request.Method,
request.RequestUri
);
Console.WriteLine("Passive: {0} Keep alive: {1} Binary: {2} Timeout: {3}.",
request.UsePassive,
request.KeepAlive,
request.UseBinary,
request.Timeout == -1 ? "none" : request.Timeout.ToString()
);
IWebProxy proxy = request.Proxy;
if (proxy != null)
{
Console.WriteLine("Proxy: {0}", proxy.GetProxy(request.RequestUri));
}
else
{
Console.WriteLine("Proxy: (none)");
}
Console.WriteLine("ConnectionGroup: {0}",
request.ConnectionGroupName == null ? "none" : request.ConnectionGroupName
);
Console.WriteLine("Encrypted connection: {0}",
request.EnableSsl);
Console.WriteLine("Method: {0}", request.Method);
}
備註
UsePassive將屬性設定為true
將 「PASV"
命令傳送至伺服器。 此命令會要求伺服器接聽數據埠,並等候連線,而不是在收到傳輸命令時起始連線。
如需使用 UsePassive指定之行為的描述,請參閱 RFC 959:「檔案傳輸通訊協定」,第 3.2 節:「建立數據連線」和第 4.1.2 節:「傳輸參數命令」。
在呼叫、 或 方法之後變更UsePassive會導致例外狀況。BeginGetRequestStreamBeginGetResponseGetResponseGetRequestStreamInvalidOperationException
如果 UsePassive 設定為 true
,FTP 伺服器可能不會傳送檔案的大小,而且下載進度一律為零。 如果 UsePassive 設定為 false
,防火牆可能會引發警示並封鎖檔案下載。