Exemple #1
0
        public static List <FileSystemFTPInfo> ConvertFrom(FtpItemCollection results, FtpClientExt ftpCmdInstance)
        {
            List <FileSystemFTPInfo> _list = new List <FileSystemFTPInfo>(results.Count);

            foreach (FtpItem item in results)
            {
                FileSystemFTPInfo info = (item.ItemType == FtpItemType.Directory)
               ? (FileSystemFTPInfo) new DirectoryFTPInfo(ftpCmdInstance, item.FullPath)
               : new FileFTPInfo(ftpCmdInstance, item.FullPath);
                // Set it to be offline to allow explorer some extra time to find details before timg out.
                info.attributes = (item.ItemType == FtpItemType.Directory) ? FileAttributes.Directory : FileAttributes.Offline;
                if (item.Attributes[0] == 'l')
                {
                    info.attributes |= FileAttributes.ReparsePoint;
                }
                // drwx-
                if ((item.Attributes[1] == 'r') &&
                    (item.Attributes[2] != 'w')
                    )
                {
                    info.attributes |= FileAttributes.ReadOnly;
                }
                info.length           = item.Size;
                info.creationTimeUtc  = item.Modified;
                info.lastWriteTimeUtc = item.Modified;
                _list.Add(info);
            }
            return(_list);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }