Пример #1
0
        /// <summary>
        /// List the files in the specified directory.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public override string[] ListFiles(string path)
        {
            path = CombinePath(m_path, path);
            if (!path.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                path += "/";
            }
            ArrayList dirList = new ArrayList();

            //note: some FTP servers have problems listing directories with spaces in them,
            //so we need to change the directory and then do a simple listing instead
            if (pushDirectory(path))
            {
                try
                {
                    Win32_Find_Data[] findData = WinInet.FtpFind(m_hFtp, "*.*");
                    for (int i = 0; i < findData.Length; i++)
                    {
                        if ((findData[i].dwFileAttributes & (int)FileAttributes.Directory) == 0)
                        {
                            dirList.Add(findData[i].cFileName);
                        }
                    }
                }
                finally
                {
                    popDirectory();
                }
            }
            return((string[])ArrayHelper.CollectionToArray(dirList, typeof(string)));
        }
Пример #2
0
        /// <summary>
        /// This method is called to determine whether a file exists.
        /// </summary>
        /// <param name="path">The file</param>
        /// <returns>true indicates the file exists, false indicates it doesn't</returns>
        override public bool FileExists(string path)
        {
            path = CombinePath(m_path, path);
            string fname = path;
            string dir   = "";

            int index = path.LastIndexOf("/", StringComparison.OrdinalIgnoreCase);

            if (index != -1)
            {
                fname = path.Substring(index + 1);
                dir   = path.Substring(0, index);
            }
            if (pushDirectory(dir))
            {
                try
                {
                    Win32_Find_Data[] files = WinInet.FtpFind(m_hFtp, fname);
                    if (files.Length > 0)
                    {
                        return(true);
                    }
                }
                finally
                {
                    popDirectory();
                }
            }
            return(false);
        }