Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
 void CreateDTP()
 {
     _currentDTP = null;
     lock (this)
     {
         if (!_disposed)
         {
             _currentDTP = new Cmd_RunDTP(_client);
         }
     }
     CheckDisposed();
 }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 void CreateDTP()
 {
     _currentDTP = null;
     lock (this)
     {
         if (!_disposed)
         {
             _currentDTP = new Cmd_RunDTP(_client);
         }
     }
     if (_disposed)
     {
         throw new ObjectDisposedException("Cmd_PutFile");
     }
 }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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();
            }
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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();
            }
        }
Exemplo n.º 13
0
        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);
        }