public BeginGetRequestStream ( AsyncCallback callback, object state ) : IAsyncResult | ||
callback | AsyncCallback | |
state | object | |
return | IAsyncResult |
public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(this);
NetEventSource.Info(this, $"Method: {_methodInfo.Method}");
}
ContextAwareResult asyncResult = null;
try
{
if (_getRequestStreamStarted)
{
throw new InvalidOperationException(SR.net_repcall);
}
_getRequestStreamStarted = true;
if (!_methodInfo.IsUpload)
{
throw new ProtocolViolationException(SR.net_nouploadonget);
}
CheckError();
FinishRequestStage(RequestStage.RequestStarted);
asyncResult = new ContextAwareResult(true, true, this, state, callback);
lock (asyncResult.StartPostingAsyncOp())
{
_writeAsyncResult = asyncResult;
SubmitRequest(true);
asyncResult.FinishPostingAsyncOp();
FinishRequestStage(RequestStage.CheckForError);
}
}
catch (Exception exception)
{
if (NetEventSource.IsEnabled) NetEventSource.Error(this, exception);
throw;
}
finally
{
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}
return asyncResult;
}
FtpWebRequest::BeginGetRequestStream ( System callback, object state ) : System.IAsyncResult |
private void UploadNextFile(IAsyncResult ar) { //清空 _currLength = 0; _abort = false; if (_uploadResponse != null) _uploadResponse.Close(); if (_fileStream != null) _fileStream.Close(); if (_requestStream != null) _requestStream.Close(); _uploadResponse = (FtpWebResponse)_uploadRequest.EndGetResponse(ar); //_result = "文件上传成功"; try { if (_uploadFiles.Count != 0) { FileInfo file = _uploadFiles[0] as FileInfo; ServerFileInfo serverFile = SearchFile(file.Name.Replace('#', '_')); if (serverFile != null) _currLength = serverFile.Size; else _currLength = 0; string uploadUrl = @"ftp://" + this.Address + ":" + this.Port + "/" + file.Name.Replace('#', '_'); _uploadRequest = (FtpWebRequest)WebRequest.Create(uploadUrl); if ((bool)_uploadFilesStateTable[file]) {//覆盖 _uploadRequest.Method = WebRequestMethods.Ftp.UploadFile; _currLength = 0; } else _uploadRequest.Method = _currLength == 0 ? WebRequestMethods.Ftp.UploadFile : WebRequestMethods.Ftp.AppendFile; _uploadRequest.Credentials = new NetworkCredential(this.UserName, this.Password); _uploadRequest.Proxy = null; _uploadRequest.KeepAlive = false; _uploadRequest.BeginGetRequestStream(new AsyncCallback(TransFile), file); } } catch (Exception e) { _result = e.Message; } }