internal IAsyncResult BeginExecute(int timeout, Stream userStream, long length, AsyncCallback cb, object state) { PutFileUnique_SO stateObj = null; SetProgress(true); _uniqueFileName = null; try { CreateDTP(); stateObj = new PutFileUnique_SO(userStream, cb, state); _cc.ResponseReceived += new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived); string cmd = "STOU"; _currentDTP.BeginExecute(timeout, cmd, _client.DataType, -1, new DTPStreamCommon(userStream, DTPStreamType.ForReading, length), new AsyncCallback(this.RunDTP_End), stateObj); } catch (Exception e) { if (null != _currentDTP) { _currentDTP.Dispose(); _currentDTP = null; } _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived); SetProgress(false); throw e; } return(stateObj); }
void RunDTP_End(IAsyncResult ar) { PutFileUnique_SO stateObj = (PutFileUnique_SO)ar.AsyncState; try { stateObj.UpdateContext(); _currentDTP.EndExecute(ar); } catch (Exception e) { stateObj.Exception = e; } finally { _currentDTP.Dispose(); _currentDTP = null; _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived); stateObj.SetCompleted(); } }