Exemplo n.º 1
0
        public bool DirectoryExists(string path)
        {
            bool flag;

            WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA();
            IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, path, ref findFileData, 0x4000000, IntPtr.Zero);

            try
            {
                if (hInternet == IntPtr.Zero)
                {
                    return(false);
                }

                flag = true;
            }
            finally
            {
                if (hInternet != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hInternet);
                }
            }

            return(flag);
        }
Exemplo n.º 2
0
        private List <string> List(string mask, bool onlyDirectories)
        {
            List <string> list2;

            WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA();
            IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, mask, ref findFileData, 0x4000000, IntPtr.Zero);

            try
            {
                List <string> list = new List <string>();
                if (hInternet == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() != 0x12)
                    {
                        this.Error();
                    }

                    return(list);
                }

                if (onlyDirectories && ((findFileData.dfFileAttributes & 0x10) == 0x10))
                {
                    list.Add(new string(findFileData.fileName).TrimEnd(new char[1]));
                }
                else if (!onlyDirectories)
                {
                    list.Add(new string(findFileData.fileName).TrimEnd(new char[1]));
                }

                for (findFileData = new WINAPI.WIN32_FIND_DATA();
                     WININET.InternetFindNextFile(hInternet, ref findFileData) != 0;
                     findFileData = new WINAPI.WIN32_FIND_DATA())
                {
                    if (onlyDirectories && ((findFileData.dfFileAttributes & 0x10) == 0x10))
                    {
                        list.Add(new string(findFileData.fileName).TrimEnd(new char[1]));
                    }
                    else if (!onlyDirectories)
                    {
                        list.Add(new string(findFileData.fileName).TrimEnd(new char[1]));
                    }
                }

                if (Marshal.GetLastWin32Error() != 0x12)
                {
                    this.Error();
                }

                list2 = list;
            }
            finally
            {
                if (hInternet != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hInternet);
                }
            }

            return(list2);
        }
Exemplo n.º 3
0
 public static extern int InternetFindNextFile([In] IntPtr hInternet,
                                               [In, Out] ref WINAPI.WIN32_FIND_DATA findData);
Exemplo n.º 4
0
        public FtpFileInfo[] GetFiles(string mask)
        {
            FtpFileInfo[]          infoArray;
            WINAPI.WIN32_FIND_DATA findFileData = new WINAPI.WIN32_FIND_DATA();
            IntPtr hInternet = WININET.FtpFindFirstFile(this._hConnect, mask, ref findFileData, 0x4000000, IntPtr.Zero);

            try
            {
                List <FtpFileInfo> list = new List <FtpFileInfo>();
                if (hInternet == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() != 0x12)
                    {
                        this.Error();
                    }

                    return(list.ToArray());
                }

                if ((findFileData.dfFileAttributes & 0x10) != 0x10)
                {
                    FtpFileInfo item = new FtpFileInfo(this, new string(findFileData.fileName).TrimEnd(new char[1]))
                    {
                        LastAccessTime = findFileData.ftLastAccessTime.ToDateTime(),
                        LastWriteTime  = findFileData.ftLastWriteTime.ToDateTime(),
                        CreationTime   = findFileData.ftCreationTime.ToDateTime(),
                        Attributes     = (FileAttributes)findFileData.dfFileAttributes
                    };
                    list.Add(item);
                }

                for (findFileData = new WINAPI.WIN32_FIND_DATA();
                     WININET.InternetFindNextFile(hInternet, ref findFileData) != 0;
                     findFileData = new WINAPI.WIN32_FIND_DATA())
                {
                    if ((findFileData.dfFileAttributes & 0x10) != 0x10)
                    {
                        FtpFileInfo info2 =
                            new FtpFileInfo(this, new string(findFileData.fileName).TrimEnd(new char[1]))
                        {
                            LastAccessTime = findFileData.ftLastAccessTime.ToDateTime(),
                            LastWriteTime  = findFileData.ftLastWriteTime.ToDateTime(),
                            CreationTime   = findFileData.ftCreationTime.ToDateTime(),
                            Attributes     = (FileAttributes)findFileData.dfFileAttributes
                        };
                        list.Add(info2);
                    }
                }

                if (Marshal.GetLastWin32Error() != 0x12)
                {
                    this.Error();
                }

                infoArray = list.ToArray();
            }
            finally
            {
                if (hInternet != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hInternet);
                }
            }

            return(infoArray);
        }
Exemplo n.º 5
0
 public static extern IntPtr FtpFindFirstFile([In] IntPtr hConnect, [In] string searchFile,
                                              [In, Out] ref WINAPI.WIN32_FIND_DATA findFileData, [In] int dwFlags, [In] IntPtr dwContext);