internal string Execute(int timeout, Stream userStream, long length) { SetProgress(true); _uniqueFileName = null; try { CreateDTP(); string cmd = "STOU"; _cc.ResponseReceived += new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived); _currentDTP.Execute(timeout, cmd, _client.DataType, -1, new DTPStreamCommon(userStream, DTPStreamType.ForReading, length)); } finally { if (null != _currentDTP) { _currentDTP.Dispose(); _currentDTP = null; } _cc.ResponseReceived -= new FtpControlConnection.ResponseReceivedEventHandler(CC_ResponseReceived); SetProgress(false); } return(_uniqueFileName); }
internal void Execute(int timeout, Stream userStream, string file, long length) { SetProgress(true); try { CreateDTP(); string cmd = "STOR " + file; _currentDTP.Execute(timeout, cmd, _client.DataType, -1, new DTPStreamCommon(userStream, DTPStreamType.ForReading, length)); } finally { if (null != _currentDTP) { _currentDTP.Dispose(); _currentDTP = null; } SetProgress(false); } }
void CreateDTP() { _currentDTP = null; lock (this) { if (!_disposed) { _currentDTP = new Cmd_RunDTP(_client); } } CheckDisposed(); }
internal IAsyncResult BeginExecute(int timeout, string path, AsyncCallback cb, object state) { List_SO stateObj = null; SetProgress(true); try { CreateDTP(); stateObj = new List_SO(new DTPStreamCommon(Stream.Null, DTPStreamType.ForWriting), cb, state); _linesBuilder.NewLineEvent += new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent); _items.Clear(); _linesBuilder.Reset(); string cmd = "LIST"; if (null != path) { cmd += " " + path; } _currentDTP.DataTransfered += new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered); try { _currentDTP.BeginExecute(timeout, cmd, FtpDataType.Ascii, -1, stateObj.UserStream, new AsyncCallback(RunCmd_End), stateObj); } catch (Exception e) { _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered); throw e; } } catch (Exception e) { if (null != _currentDTP) { _currentDTP.Dispose(); _currentDTP = null; } SetProgress(false); throw e; } return(stateObj); }
void CreateDTP() { _currentDTP = null; lock (this) { if (!_disposed) { _currentDTP = new Cmd_RunDTP(_client); } } if (_disposed) { throw new ObjectDisposedException("Cmd_PutFile"); } }
internal FtpItem[] Execute(int timeout, string dir) { FtpItem[] items = null; SetProgress(true); try { CreateDTP(); _linesBuilder.NewLineEvent += new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent); _items.Clear(); _linesBuilder.Reset(); string cmd = "LIST"; if (null != dir) { cmd += " " + dir; } _currentDTP.DataTransfered += new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered); try { _currentDTP.Execute(timeout, cmd, FtpDataType.Ascii, -1, new DTPStreamCommon(Stream.Null, DTPStreamType.ForWriting)); } finally { _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered); } items = new FtpItem[_items.Count]; _items.CopyTo(items); } finally { if (null != _currentDTP) { _currentDTP.Dispose(); _currentDTP = null; } _linesBuilder.NewLineEvent -= new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent); SetProgress(false); } return(items); }
void Lock_End(object state, bool timedout) { Reset_SO stateObj = (Reset_SO)state; try { stateObj.UpdateContext(); if (timedout) { string msg = string.Format("Unable to lock CC within {0} time: ", stateObj.Timeout); NSTrace.WriteLineError(msg + Environment.StackTrace); stateObj.Exception = GetTimeoutException(stateObj.Timeout); stateObj.SetCompleted(); } else { try { Cmd_RunDTP curDTP = _client.CurrentDTP; if (null != curDTP) { curDTP.Reset(); } } finally { _cc.Unlock(); } //---------------------------------------- //Wait till DTP finishes _client.BeginWaitForDTPFinished(stateObj.Timeout, new WaitOrTimerCallback(DTPFinishedWait_End), stateObj); } } catch (Exception e) { stateObj.Exception = e; stateObj.SetCompleted(); } }
void RunDTP_End(IAsyncResult ar) { PutFile_SO stateObj = (PutFile_SO)ar.AsyncState; try { stateObj.UpdateContext(); _currentDTP.EndExecute(ar); } catch (Exception e) { stateObj.Exception = e; } finally { _currentDTP.Dispose(); _currentDTP = null; stateObj.SetCompleted(); } }
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(); } }
internal void Execute(int timeout) { bool finished = false; //--------------------------------- //Lock CC if (_cc.Lock(timeout)) { //------------------------------------------ //Reset DTP try { Cmd_RunDTP curDTP = _client.CurrentDTP; if (null != curDTP) { curDTP.Reset(); } } finally { _cc.Unlock(); } //------------------------------------------ //Wait till DTP exits finished = _client.WaitForDTPFinish(timeout); if (!finished) { string msg = string.Format("DTP is not finished withing {0} time: ", timeout); NSTrace.WriteLineError(msg + Environment.StackTrace); throw GetTimeoutException(timeout); } } else { string msg = string.Format("Unable to lock CC within {0} time: ", timeout); NSTrace.WriteLineError(msg + Environment.StackTrace); throw GetTimeoutException(timeout); } }
void RunCmd_End(IAsyncResult ar) { List_SO stateObj = (List_SO)ar.AsyncState; try { stateObj.UpdateContext(); _currentDTP.EndExecute(ar); } catch (Exception e) { stateObj.Exception = e; } finally { _currentDTP.DataTransfered -= new Cmd_RunDTP.DataTransferedEventHandler(List_OnDataTransfered); _currentDTP.Dispose(); _currentDTP = null; _linesBuilder.NewLineEvent -= new LinesBuilder.NewLineEventHandler(List_OnNewLineEvent); stateObj.SetCompleted(); } }
internal IAsyncResult BeginExecute(int timeout, Stream userStream, string fileName, long length, AsyncCallback cb, object state) { PutFile_SO stateObj = null; SetProgress(true); try { CreateDTP(); stateObj = new PutFile_SO(userStream, cb, state); string cmd = "STOR " + fileName; _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; } SetProgress(false); throw e; } return(stateObj); }