FtpWebRequest.GetRequestStream Yöntem

Tanım

Ftp sunucusuna veri yüklemek için kullanılan akışı alır.

public:
 override System::IO::Stream ^ GetRequestStream();
public override System.IO.Stream GetRequestStream ();
override this.GetRequestStream : unit -> System.IO.Stream
Public Overrides Function GetRequestStream () As Stream

Döndürülenler

Geçerli istek tarafından sunucuya gönderilecek verileri depolamak için kullanılan yazılabilir Stream bir örnek.

Özel durumlar

BeginGetRequestStream(AsyncCallback, Object) çağrıldı ve tamamlanmadı.

-veya-

HTTP proxy'si etkinleştirildi ve , ListDirectoryveya ListDirectoryDetailsdışında DownloadFilebir FTP komutu kullanmayı denediniz.

FTP sunucusuyla bağlantı kurulamadı.

Method özelliği veya AppendFileolarak UploadFile ayarlanmadı.

Örnekler

Aşağıdaki kod örneği, bir dosyanın isteğin veri akışına kopyalanmasını ve verileri karşıya yükleyip bir dosyaya eklemesi için sunucuya istek göndermeyi gösterir.

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 = dynamic_cast<FtpWebRequest^>(WebRequest::Create( serverUri ));
   request->Method = WebRequestMethods::Ftp::AppendFile;
   StreamReader^ sourceStream = gcnew StreamReader( fileName );
   array<Byte>^fileContents = Encoding::UTF8->GetBytes( sourceStream->ReadToEnd() );
   sourceStream->Close();
   request->ContentLength = fileContents->Length;

   // This example assumes the FTP site uses anonymous logon.
   request->Credentials = gcnew NetworkCredential( "anonymous","janeDoe@contoso.com" );
   Stream^ requestStream = request->GetRequestStream();
   requestStream->Write( fileContents, 0, fileContents->Length );
   requestStream->Close();
   FtpWebResponse^ response = dynamic_cast<FtpWebResponse^>(request->GetResponse());
   Console::WriteLine( "Append status: {0}", response->StatusDescription );
   response->Close();
   return true;
}
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());
    sourceStream.Close();
    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);
    requestStream.Close();
    FtpWebResponse response = (FtpWebResponse) request.GetResponse();

    Console.WriteLine("Append status: {0}",response.StatusDescription);

    response.Close();
    return true;
}

Açıklamalar

yöntemini çağırmadan GetRequestStream önce istek özelliklerini ayarlayın. Verileri akışa yazdıktan sonra, isteği göndermeden önce akışı kapatmanız gerekir.

özelliğini UploadFile veya AppendFileolarak ayarlamadıysanız Method akışı alamazsınız.

GetRequestStream akış beklerken bloklar. Bunu önlemek için yerine yöntemini çağırın BeginGetRequestStreamGetRequestStream.

Not

Uygulamanızda ağ izlemeyi etkinleştirdiğinizde, bu üye izleme bilgilerini çıkarır. Daha fazla bilgi için .NET Framework ağ izleme bölümüne bakın.

Arayanlara Notlar

Bu yöntem ağ trafiği oluşturur.

Şunlara uygulanır

Ayrıca bkz.