Do we have to wait for "BeginGetRequestStream()" before continue with "BeginGetResponse()"?
If yes, so, I can change method "AllowAbortUpload()" as follows:
public void AllowAbortUpload(string fileName, string serverUri)
{
request = (FtpWebRequest)WebRequest.Create(serverUri);
request.Method = WebRequestMethods.Ftp.UploadFile;
// Get the file to be uploaded and convert it to bytes.
StreamReader sourceStream = new StreamReader(fileName);
fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
// Set the content length to the number of bytes in the file.
request.ContentLength = fileContents.Length;
// Asynchronously get the stream for the file contents.
IAsyncResult ar = request.BeginGetRequestStream(
new AsyncCallback (EndGetStreamCallback), null);
Console.WriteLine("Sending the request asynchronously...");
IAsyncResult responseAR = request.BeginGetResponse(
new AsyncCallback (EndGetResponseCallback), null);
while ((!responseAR.IsCompleted) || (!ar.IsCompleted))
{
Console.WriteLine("Press 'a' to abort the upload. Press any other key to continue.");
string input = Console.ReadLine();
if (input == "a")
{
AbortRequest(request);
return;
}
}
}
Thanks.