Bagikan melalui


FtpWebRequest.UsePassive Properti

Definisi

Mendapatkan atau mengatur perilaku proses transfer data aplikasi klien.

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

Nilai Properti

false jika proses transfer data aplikasi klien mendengarkan koneksi pada port data; jika tidak, true jika klien harus memulai koneksi pada port data. Nilai defaultnya adalah true.

Pengecualian

Nilai baru ditentukan untuk properti ini untuk permintaan yang sudah berlangsung.

Contoh

Contoh kode berikut mengambil dan menampilkan nilai properti untuk objek tertentu 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);
}

Keterangan

UsePassive Mengatur properti untuk true mengirim perintah "PASV" ke server. Perintah ini meminta server untuk mendengarkan port data dan menunggu koneksi daripada memulainya setelah menerima perintah transfer.

Untuk deskripsi perilaku yang ditentukan menggunakan UsePassive, lihat RFC 959: "Protokol Transfer File", Bagian 3.2: "Membuat Koneksi Data" dan Bagian 4.1.2: "Perintah Parameter Transfer".

Mengubah UsePassive setelah memanggil GetRequestStreammetode , BeginGetRequestStream, GetResponse, atau BeginGetResponse menyebabkan InvalidOperationException pengecualian.

Jika UsePassive diatur ke true, server FTP mungkin tidak mengirim ukuran file, dan kemajuan pengunduhan selalu bisa nol. Jika UsePassive diatur ke false, firewall dapat menaikkan pemberitahuan dan memblokir unduhan file.

Berlaku untuk

Lihat juga