Private Static Void Endgetstreamcallback (iasyncresult AR)
{
Ftpstate state = (Ftpstate) Ar. asyncstate;
Stream requeststream = Null ;
// End the asynchronous call to get the request stream.
Try
{
Requeststream = State. Request. endgetrequeststream (AR );
// Copy the file contents to the request stream.
Const Int Bufferlength = 2048 ;
Byte [] Buffer = New Byte [Bufferlength];
Int Count = 0 ;
Int Readbytes = 0 ;
Filestream stream = File. openread (State. filename );
Do
{
Readbytes = Stream. Read (buffer, 0 , Bufferlength );
Requeststream. Write (buffer, 0 , Readbytes );
Count + = Readbytes;
}
While (Readbytes ! = 0 );
Console. writeline ( " Writing {0} bytes to the stream. " , Count );
// Important: Close the request stream before sending the request.
Requeststream. Close ();
// Asynchronously get the response to the upload request.
State. Request. begingetresponse (
New Asynccallback (endgetresponsecallback ),
State
);
}
// Return exceptions to the main application thread.
Catch (Exception E)
{
Console. writeline ( " Cocould not get the request stream. " );
State. operationexception = E;
State. operationcomplete. Set ();
Return ;
}
}