Example #1
0
 /// <summary>
 /// Constructor for FtpResponse.
 /// </summary>
 /// <param name="response">FtpResponse object.</param>
 public FtpResponse(FtpResponse response)
 {
     _rawText = response.RawText;
     _text = response.Text;
     _code = response.Code;
     _isInformational = response.IsInformational;
 }
Example #2
0
        private bool IsHappyResponse(FtpResponse response, FtpResponseCode[] happyResponseCodes)
        {
            // always return true if there are no responses to validate
            if (happyResponseCodes.Length == 0)
                return true;

            return happyResponseCodes.Any(t => t == response.Code);
        }
Example #3
0
 private bool IsUnhappyResponse(FtpResponse response)
 {
     if (
         response.Code == FtpResponseCode.ServiceNotAvailableClosingControlConnection
         || response.Code == FtpResponseCode.CannotOpenDataConnection
         || response.Code == FtpResponseCode.ConnectionClosedSoTransferAborted
         || response.Code == FtpResponseCode.RequestedFileActionNotTaken
         || response.Code == FtpResponseCode.RequestedActionAbortedDueToLocalErrorInProcessing
         || response.Code == FtpResponseCode.RequestedActionNotTakenInsufficientStorage
         || response.Code == FtpResponseCode.SyntaxErrorCommandUnrecognized
         || response.Code == FtpResponseCode.SyntaxErrorInParametersOrArguments
         || response.Code == FtpResponseCode.CommandNotImplemented
         || response.Code == FtpResponseCode.BadSequenceOfCommands
         || response.Code == FtpResponseCode.CommandNotImplementedForThatParameter
         || response.Code == FtpResponseCode.NotLoggedIn
         || response.Code == FtpResponseCode.NeedAccountForStoringFiles
         || response.Code == FtpResponseCode.RequestedActionNotTakenFileUnavailable
         || response.Code == FtpResponseCode.RequestedActionAbortedPageTypeUnknown
         || response.Code == FtpResponseCode.RequestedFileActionAbortedExceededStorageAllocation
         || response.Code == FtpResponseCode.RequestedActionNotTakenFileNameNotAllowed)
         return true;
     return false;
 }
Example #4
0
 private void RaiseServerResponseEvent(FtpResponse response)
 {
     if (ServerResponse != null)
         ServerResponse(this, new FtpResponseEventArgs(response));
 }
Example #5
0
        /// <summary>
        ///     Waits until a happy code has been returned by the FTP server or times out.
        /// </summary>
        /// <param name="timeout">Maximum time to wait before timing out.</param>
        /// <param name="happyResponseCodes">Server response codes to wait for.</param>
        protected internal void WaitForHappyCodes(int timeout, params FtpResponseCode[] happyResponseCodes)
        {
            _responseList.Clear();
            do
            {
                FtpResponse response = GetNextCommandResponse(timeout);
                _responseList.Add(response);
                RaiseServerResponseEvent(new FtpResponse(response));

                if (!response.IsInformational)
                {
                    if (IsHappyResponse(response, happyResponseCodes))
                        break;

                    if (IsUnhappyResponse(response))
                        throw new FtpException(response.Text);
                }
            } while (true);

            _response = _responseList.GetLast();
        }
Example #6
0
        private void DontWaitForHappyCodes()
        {
            if (_responseQueue.Count == 0)
                return;

            _responseList.Clear();
            while (_responseQueue.Count > 0)
            {
                FtpResponse response = _responseQueue.Dequeue();
                _responseList.Add(response);
                RaiseServerResponseEvent(new FtpResponse(response));
            }
            _response = _responseList.GetLast();
        }