Exemplo n.º 1
0
        /// <summary>
        /// Get as many details as it can about the target.
        /// </summary>
        /// <param name="target">If empty then will assume CWD has been used</param>
        /// <returns>May return null if nothing found</returns>
        public FileSystemFTPInfo GetFileDetails(string target)
        {
            List <FileSystemFTPInfo> foundValues;

            lock (commandLock)
            {
                // replace the windows style directory delimiter with a unix style delimiter
                target = NormaliseForFTP(target);
                Features featureToUse = ((SupportedFeatures & Features.MLST) == Features.MLST)
                                       ? Features.MLST
                                       : Features.LIST;
                if (featureToUse == Features.MLST)
                {
                    happyCodes = FtpRequest.BuildResponseArray(FtpResponseCode.RequestedFileActionOkayAndCompleted,
                                                               FtpResponseCode.SyntaxErrorInParametersOrArguments // Stop using exceptions to detect missing
                                                               );
                }
                else
                {
                    happyCodes = FtpRequest.BuildResponseArray(FtpResponseCode.DataConnectionAlreadyOpenSoTransferStarting,
                                                               FtpResponseCode.FileStatusOkaySoAboutToOpenDataConnection,
                                                               FtpResponseCode.ClosingDataConnection,
                                                               FtpResponseCode.RequestedFileActionOkayAndCompleted
                                                               );
                }
                FtpResponseCollection dirResults = (string.IsNullOrEmpty(target))
                                                  ? Feature((featureToUse != Features.MLST), featureToUse)
                                                  : Feature((featureToUse != Features.MLST), featureToUse, true, target);
                if (featureToUse == Features.MLST)
                {
                    foundValues = new MlstCollection(this, target, dirResults);
                }
                else
                {
                    // Do it the harder way ??
                    FtpItemCollection results = new FtpItemCollection(target, dirResults.GetRawText(), ftpInstance.ItemParser);
                    foundValues = FileSystemFTPInfo.ConvertFrom(results, this);
                }
            }
            return(foundValues.Count > 0 ? foundValues[0] : null);
        }
Exemplo n.º 2
0
        //public bool ChangeDirectory(string path)
        //{
        //   if (path == null)
        //      throw new ArgumentNullException("path");

        //   if (path.Length == 0)
        //      throw new ArgumentException("must have a value", "path");

        //   // replace the windows style directory delimiter with a unix style delimiter
        //   path = NormaliseForFTP( path );

        //   lock (commandLock)
        //   {
        //      FtpRequest request = new FtpRequest(FtpCmd.Cwd, ftpInstance.CharacterEncoding, path)
        //                              {
        //                                 HappyCodes =
        //                                    FtpRequest.BuildResponseArray(
        //                                       FtpResponseCode.RequestedFileActionOkayAndCompleted,
        //                                       FtpResponseCode.RequestedActionNotTakenFileUnavailable
        //                                    )
        //                              };
        //      CheckConnected();
        //      ftpInstance.SendRequest(request);
        //      return ftpInstance.LastResponse.Code == FtpResponseCode.RequestedFileActionOkayAndCompleted;
        //   }
        //}

        public List <FileSystemFTPInfo> GetDirList(string path)
        {
            List <FileSystemFTPInfo> foundValues;

            lock (commandLock)
            {
                // replace the windows style directory delimiter with a unix style delimiter
                path = NormaliseForFTP(path);
                Features featureToUse = ((SupportedFeatures & Features.MLSD) == Features.MLSD)
                                       ? Features.MLSD
                                       : Features.LIST;
                if (featureToUse == Features.MLSD)
                {
                    happyCodes = FtpRequest.BuildResponseArray(FtpResponseCode.ClosingDataConnection,
                                                               FtpResponseCode.RequestedFileActionOkayAndCompleted);
                }
                else
                {
                    happyCodes = FtpRequest.BuildResponseArray(FtpResponseCode.DataConnectionAlreadyOpenSoTransferStarting,
                                                               FtpResponseCode.FileStatusOkaySoAboutToOpenDataConnection,
                                                               FtpResponseCode.ClosingDataConnection,
                                                               FtpResponseCode.RequestedFileActionOkayAndCompleted);
                }
                FtpResponseCollection dirResults = (string.IsNullOrEmpty(path))
                                                  ? Feature((featureToUse != Features.MLSD), featureToUse)
                                                  : Feature((featureToUse != Features.MLSD), featureToUse, true, path);
                if (featureToUse == Features.MLSD)
                {
                    foundValues = new MlstCollection(this, path, dirResults);
                }
                else
                {
                    // Do it the harder way ??
                    FtpItemCollection results = new FtpItemCollection(path, dirResults.GetRawText(), ftpInstance.ItemParser);
                    foundValues = FileSystemFTPInfo.ConvertFrom(results, this);
                }
            }
            return(foundValues);
        }