Esempio n. 1
0
        /// <summary>
        /// Retrieves the set of files that match the specified search string.
        /// </summary>
        /// <param name="hConnect"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static Win32_Find_Data[] FtpFind(IntPtr hConnect, string search)
        {
            ArrayList       list     = new ArrayList();
            Win32_Find_Data findData = new Win32_Find_Data();

            // Set up buffer
            int    bufferSize = Marshal.SizeOf(typeof(Win32_Find_Data)) + Kernel32.MAX_PATH + 14;
            IntPtr buffer     = Marshal.AllocCoTaskMem(bufferSize);
            IntPtr m_hFind    = FtpFindFirstFile(hConnect, search, buffer, 0, 0);

            try
            {
                if (m_hFind != IntPtr.Zero)
                {
                    findData = (Win32_Find_Data)Marshal.PtrToStructure(buffer, typeof(Win32_Find_Data));
                    list.Add(findData);

                    //Iterate over the next files
                    while (InternetFindNextFile(m_hFind, buffer))
                    {
                        findData = (Win32_Find_Data)Marshal.PtrToStructure(buffer, typeof(Win32_Find_Data));
                        list.Add(findData);
                    }
                }

                //return the list of Win32_Find_Data structures
                return((Win32_Find_Data[])list.ToArray(typeof(Win32_Find_Data)));
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
                if (m_hFind != IntPtr.Zero)
                {
                    InternetCloseHandle(m_hFind);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieves the set of files that match the specified search string.
        /// </summary>
        /// <param name="hConnect"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        public static Win32_Find_Data[] FtpFind(IntPtr hConnect, string search)
        {

            ArrayList list = new ArrayList();
            Win32_Find_Data findData = new Win32_Find_Data();

            // Set up buffer
            int bufferSize = Marshal.SizeOf(typeof(Win32_Find_Data)) + Kernel32.MAX_PATH + 14;
            IntPtr buffer = Marshal.AllocCoTaskMem(bufferSize);
            IntPtr m_hFind = FtpFindFirstFile(hConnect, search, buffer, 0, 0);
            try
            {
                if (m_hFind != IntPtr.Zero)
                {
                    findData = (Win32_Find_Data)Marshal.PtrToStructure(buffer, typeof(Win32_Find_Data));
                    list.Add(findData);

                    //Iterate over the next files
                    while (InternetFindNextFile(m_hFind, buffer))
                    {
                        findData = (Win32_Find_Data)Marshal.PtrToStructure(buffer, typeof(Win32_Find_Data));
                        list.Add(findData);
                    }
                }

                //return the list of Win32_Find_Data structures
                return (Win32_Find_Data[])list.ToArray(typeof(Win32_Find_Data));
            }
            finally
            {
                Marshal.FreeCoTaskMem(buffer);
                if (m_hFind != IntPtr.Zero) InternetCloseHandle(m_hFind);
            }
        }