示例#1
0
        /// <summary>
        /// List a directory's contents as an array of FTPFile objects.
        /// </summary>
        /// <remarks>
        /// This works for Windows and most Unix FTP servers.  Please inform EDT
        /// about unusual formats ([email protected]). Note that for some
        /// servers, this will not work from the parent directory of dirname. You
        /// need to ChDir() into dirname and use DirDetails() (with no arguments).
        /// </remarks>
        /// <param name="dirname">Name of directory OR filemask (if supported by the server).</param>
        /// <returns>An array of <see cref="FTPFile"/> objects.</returns>
        public virtual FTPFile[] DirDetails(string dirname, FTPFileCallback dirListItemCallback)
        {
            string path = SetupDirDetails(dirname);

            // now the last part of the path ... but it could be a filename or mask or a directory!
            string lastPart = dirname != null ? PathUtil.GetFileName(dirname) : "";

            // get the details and parse. Set the directory for each file
            ArrayList result = new ArrayList();
            DirProcessState state = new DirProcessState();
            state.files = result;
            state.fileFactory = fileFactory;
            state.fileCallback = dirListItemCallback;
            state.fileStrings = new ArrayList();
            Dir(dirname, true, new LineCallback(ProcessDirLine), state);

            FTPFile[] results = (FTPFile[])result.ToArray(typeof(FTPFile));

            FixPaths(results, path, lastPart);

            return results;
        }
示例#2
0
 /// <summary>
 /// Returns the given directory's contents as an array of <see cref="FTPFile"/> objects.
 /// </summary>
 /// <remarks>
 /// This method works for Windows and most Unix FTP servers.  Please inform EDT
 /// about unusual formats (<a href="*****@*****.**">[email protected]</a>).
 /// </remarks>
 /// <param name="directory">Name of directory AND/OR filemask.</param>
 /// <param name="dirListCallback">Callback to notify for each listing item</param>
 /// <returns>An array of <see cref="FTPFile"/> objects.</returns>
 public virtual FTPFile[] GetFileInfos(string directory, FTPFileCallback dirListCallback)
 {
     log.Debug("GetFileInfos('" + directory + ")");
     lock (clientLock)
     {
         FTPFile[] files = null;
         Exception ex = null;
         try
         {
             OnDirectoryListing(directory);
             isTransferringData = true;
             files = ActiveClient.DirDetails(directory, dirListCallback);
             if (files == null)
                 files = new FTPFile[0];
         }
         catch (Exception e)
         {
             ex = e;
             throw;
         }
         finally
         {
             isTransferringData = false;
             OnDirectoryListed(directory, files, ex);
         }
         return files;
     }
 }