Beispiel #1
0
        /// <summary>
        /// Gets a list of <see cref="FtpFile"/> objects from the given directory.
        /// </summary>
        /// <param name="directory">The server path to get the files from [minus the the host].</param>
        /// <returns>A list of <see cref="FtpFile"/> from the given directory.</returns>
        public List <FtpFile> FileList(string directory)
        {
            var    list = new List <FtpFile>();
            string path;
            var    output = GetFtpListOutput(directory);

            if (directory == string.Empty)
            {
                path = string.Empty;
            }
            else
            {
                path = directory.Substring(0, directory.LastIndexOf('/'));
            }

            foreach (string line in output)
            {
                var match = LineMatch(line);
                if (match == null)
                {
                    throw new ApplicationException("Unable to parse line: " + line);
                }

                FtpItem item = BuildItem(match, path);

                if (item.GetType() == typeof(FtpFile))
                {
                    list.Add(( FtpFile )item);
                }
            }

            return(list);
        }
Beispiel #2
0
        /// <summary>
        /// Checks whether the file exists on the server or not.
        /// </summary>
        /// <param name="item">The <see cref="FtpFile"/> to check.</param>
        /// <returns><c>true</c> if the file exists, otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="item"/> argument is null.
        /// </exception>
        public bool FtpItemExists(FtpItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item", "The FtpItem can not be null");
            }

            if (item.GetType() == typeof(FtpFile))
            {
                return(FtpItemExists(item.Path + item.Name, FtpItemType.File));
            }
            else
            {
                return(FtpItemExists(item.Path + item.Name, FtpItemType.Folder));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Checks whether the file exists on the server or not.
        /// </summary>
        /// <param name="item">The <see cref="FtpFile"/> to check.</param>
        /// <returns><c>true</c> if the file exists, otherwise, <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="item"/> argument is null.
        /// </exception>
        public bool FtpItemExists( FtpItem item )
        {
            if( item == null ) {
                throw new ArgumentNullException( "item", "The FtpItem can not be null" );
            }

            if( item.GetType() == typeof( FtpFile ) ) {
                return FtpItemExists( item.Path + item.Name, FtpItemType.File );
            }
            else {
                return FtpItemExists( item.Path + item.Name, FtpItemType.Folder );
            }
        }