コード例 #1
0
ファイル: FtpConnection.cs プロジェクト: vlad1000/ModioX
        /// <summary>
        /// Gets details of all directories and their available FTP directory information from the current working FTP directory that match the directory mask.
        /// </summary>
        /// <returns>A <see cref="FtpDirectoryInfo[]"/> representing the directories in the current working directory that match the mask.</returns>
        public FtpDirectoryInfo[] GetDirectories(string path)
        {
            WINAPI.WIN32_FIND_DATA findData = new WINAPI.WIN32_FIND_DATA();

            IntPtr hFindFile = WININET.FtpFindFirstFile(
                _hConnect,
                path,
                ref findData,
                WININET.INTERNET_FLAG_NO_CACHE_WRITE,
                IntPtr.Zero);

            try
            {
                List <FtpDirectoryInfo> directories = new List <FtpDirectoryInfo>();

                if (hFindFile == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == WINAPI.ERROR_NO_MORE_FILES)
                    {
                        return(directories.ToArray());
                    }
                    else
                    {
                        Error();
                        return(directories.ToArray());
                    }
                }

                if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) == WINAPI.FILE_ATTRIBUTE_DIRECTORY)
                {
                    FtpDirectoryInfo dir = new FtpDirectoryInfo(this, new string(findData.fileName).TrimEnd('\0'))
                    {
                        LastAccessTime = findData.ftLastAccessTime.ToDateTime(),
                        LastWriteTime  = findData.ftLastWriteTime.ToDateTime(),
                        CreationTime   = findData.ftCreationTime.ToDateTime(),
                        Attributes     = (FileAttributes)findData.dfFileAttributes
                    };
                    directories.Add(dir);
                }

                findData = new WINAPI.WIN32_FIND_DATA();

                while (WININET.InternetFindNextFile(hFindFile, ref findData) != 0)
                {
                    if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) == WINAPI.FILE_ATTRIBUTE_DIRECTORY)
                    {
                        FtpDirectoryInfo dir = new FtpDirectoryInfo(this, new string(findData.fileName).TrimEnd('\0'))
                        {
                            LastAccessTime = findData.ftLastAccessTime.ToDateTime(),
                            LastWriteTime  = findData.ftLastWriteTime.ToDateTime(),
                            CreationTime   = findData.ftCreationTime.ToDateTime(),
                            Attributes     = (FileAttributes)findData.dfFileAttributes
                        };
                        directories.Add(dir);
                    }

                    findData = new WINAPI.WIN32_FIND_DATA();
                }

                if (Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES)
                {
                    Error();
                }

                return(directories.ToArray());
            }
            finally
            {
                if (hFindFile != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hFindFile);
                }
            }
        }
コード例 #2
0
        public FtpFileInfo[] GetFiles(string mask)
        {
            FtpFileInfo[]          infoArray;
            WINAPI.WIN32_FIND_DATA findFileData = new();
            IntPtr hInternet = WININET.FtpFindFirstFile(_hConnect, mask, ref findFileData, 0x400_0000, IntPtr.Zero);

            try
            {
                List <FtpFileInfo> list = new();
                if (hInternet == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == 0x12)
                    {
                        infoArray = list.ToArray();
                    }
                    else
                    {
                        Error();
                        infoArray = list.ToArray();
                    }
                }
                else
                {
                    if ((findFileData.dfFileAttributes & 0x10) != 0x10)
                    {
                        FtpFileInfo item = new(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);
                    }

                    findFileData = new WINAPI.WIN32_FIND_DATA();
                    while (true)
                    {
                        if (WININET.InternetFindNextFile(hInternet, ref findFileData) == 0)
                        {
                            if (Marshal.GetLastWin32Error() != 0x12)
                            {
                                Error();
                            }
                            infoArray = list.ToArray();
                            break;
                        }

                        if ((findFileData.dfFileAttributes & 0x10) != 0x10)
                        {
                            FtpFileInfo item = new(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);
                        }

                        findFileData = new WINAPI.WIN32_FIND_DATA();
                    }
                }
            }
            finally
            {
                if (hInternet != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hInternet);
                }
            }

            return(infoArray);
        }
コード例 #3
0
ファイル: FtpConnection.cs プロジェクト: vlad1000/ModioX
        private List <string> List(string mask, bool onlyDirectories)
        {
            WINAPI.WIN32_FIND_DATA findData = new WINAPI.WIN32_FIND_DATA();

            IntPtr hFindFile = WININET.FtpFindFirstFile(
                _hConnect,
                mask,
                ref findData,
                WININET.INTERNET_FLAG_NO_CACHE_WRITE,
                IntPtr.Zero);

            try
            {
                List <string> files = new List <string>();
                if (hFindFile == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == WINAPI.ERROR_NO_MORE_FILES)
                    {
                        return(files);
                    }
                    else
                    {
                        Error();
                        return(files);
                    }
                }

                if (onlyDirectories && (findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) == WINAPI.FILE_ATTRIBUTE_DIRECTORY)
                {
                    files.Add(new string(findData.fileName).TrimEnd('\0'));
                }
                else if (!onlyDirectories)
                {
                    files.Add(new string(findData.fileName).TrimEnd('\0'));
                }

                findData = new WINAPI.WIN32_FIND_DATA();
                while (WININET.InternetFindNextFile(hFindFile, ref findData) != 0)
                {
                    if (onlyDirectories && (findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) == WINAPI.FILE_ATTRIBUTE_DIRECTORY)
                    {
                        files.Add(new string(findData.fileName).TrimEnd('\0'));
                    }
                    else if (!onlyDirectories)
                    {
                        files.Add(new string(findData.fileName).TrimEnd('\0'));
                    }
                    findData = new WINAPI.WIN32_FIND_DATA();
                }

                if (Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES)
                {
                    Error();
                }

                return(files);
            }
            finally
            {
                if (hFindFile != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hFindFile);
                }
            }
        }
コード例 #4
0
ファイル: FtpConnection.cs プロジェクト: Doregon/ModioX
        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(_hConnect, mask, ref findFileData, 0x400_0000, IntPtr.Zero);

            try
            {
                List <string> list = new List <string>();
                if (hInternet == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == 0x12)
                    {
                        list2 = list;
                    }
                    else
                    {
                        Error();
                        list2 = list;
                    }
                }
                else
                {
                    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]));
                    }
                    findFileData = new WINAPI.WIN32_FIND_DATA();
                    while (true)
                    {
                        if (WININET.InternetFindNextFile(hInternet, ref findFileData) == 0)
                        {
                            if (Marshal.GetLastWin32Error() != 0x12)
                            {
                                Error();
                            }
                            list2 = list;
                            break;
                        }
                        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]));
                        }
                        findFileData = new WINAPI.WIN32_FIND_DATA();
                    }
                }
            }
            finally
            {
                if (hInternet != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(hInternet);
                }
            }
            return(list2);
        }