Esempio n. 1
0
        public bool FileExists(string path)
        {
            var findFileData = default(WINAPI.WIN32_FIND_DATA);
            var intPtr       = WININET.FtpFindFirstFile(_hConnect, path, ref findFileData, 67108864, IntPtr.Zero);

            try
            {
                if (intPtr == IntPtr.Zero)
                {
                    return(false);
                }
                return(true);
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(intPtr);
                }
            }
        }
Esempio n. 2
0
        public FtpDirectoryInfo[] GetDirectories(string path)
        {
            var findFileData = default(WINAPI.WIN32_FIND_DATA);
            var intPtr       = WININET.FtpFindFirstFile(_hConnect, path, ref findFileData, 67108864, IntPtr.Zero);

            try
            {
                var list = new List <FtpDirectoryInfo>();
                if (intPtr == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == 18)
                    {
                        return(list.ToArray());
                    }
                    Error();
                    return(list.ToArray());
                }

                if ((findFileData.dfFileAttributes & 0x10) == 16)
                {
                    var text             = new string(findFileData.fileName);
                    var trimChars        = new char[1];
                    var ftpDirectoryInfo = new FtpDirectoryInfo(this, text.TrimEnd(trimChars));
                    ftpDirectoryInfo.LastAccessTime = findFileData.ftLastAccessTime.ToDateTime();
                    ftpDirectoryInfo.LastWriteTime  = findFileData.ftLastWriteTime.ToDateTime();
                    ftpDirectoryInfo.CreationTime   = findFileData.ftCreationTime.ToDateTime();
                    ftpDirectoryInfo.Attributes     = (FileAttributes)findFileData.dfFileAttributes;
                    list.Add(ftpDirectoryInfo);
                }

                findFileData = default;
                while (WININET.InternetFindNextFile(intPtr, ref findFileData) != 0)
                {
                    if ((findFileData.dfFileAttributes & 0x10) == 16)
                    {
                        var text2             = new string(findFileData.fileName);
                        var trimChars2        = new char[1];
                        var ftpDirectoryInfo2 = new FtpDirectoryInfo(this, text2.TrimEnd(trimChars2));
                        ftpDirectoryInfo2.LastAccessTime = findFileData.ftLastAccessTime.ToDateTime();
                        ftpDirectoryInfo2.LastWriteTime  = findFileData.ftLastWriteTime.ToDateTime();
                        ftpDirectoryInfo2.CreationTime   = findFileData.ftCreationTime.ToDateTime();
                        ftpDirectoryInfo2.Attributes     = (FileAttributes)findFileData.dfFileAttributes;
                        list.Add(ftpDirectoryInfo2);
                    }

                    findFileData = default;
                }

                if (Marshal.GetLastWin32Error() != 18)
                {
                    Error();
                }
                return(list.ToArray());
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(intPtr);
                }
            }
        }
Esempio n. 3
0
        private List <string> List(string mask, bool onlyDirectories)
        {
            WINAPI.WIN32_FIND_DATA findFileData = default;
            var intPtr = WININET.FtpFindFirstFile(_hConnect, mask, ref findFileData, 67108864, IntPtr.Zero);

            try
            {
                var list = new List <string>();
                if (intPtr == IntPtr.Zero)
                {
                    if (Marshal.GetLastWin32Error() == 18)
                    {
                        return(list);
                    }
                    Error();
                    return(list);
                }

                if (onlyDirectories && (findFileData.dfFileAttributes & 0x10) == 16)
                {
                    var list2     = list;
                    var text      = new string(findFileData.fileName);
                    var trimChars = new char[1];
                    list2.Add(text.TrimEnd(trimChars));
                }
                else if (!onlyDirectories)
                {
                    var list3      = list;
                    var text2      = new string(findFileData.fileName);
                    var trimChars2 = new char[1];
                    list3.Add(text2.TrimEnd(trimChars2));
                }

                findFileData = default;
                while (WININET.InternetFindNextFile(intPtr, ref findFileData) != 0)
                {
                    if (onlyDirectories && (findFileData.dfFileAttributes & 0x10) == 16)
                    {
                        var list4      = list;
                        var text3      = new string(findFileData.fileName);
                        var trimChars3 = new char[1];
                        list4.Add(text3.TrimEnd(trimChars3));
                    }
                    else if (!onlyDirectories)
                    {
                        var list5      = list;
                        var text4      = new string(findFileData.fileName);
                        var trimChars4 = new char[1];
                        list5.Add(text4.TrimEnd(trimChars4));
                    }

                    findFileData = default;
                }

                if (Marshal.GetLastWin32Error() != 18)
                {
                    Error();
                }
                return(list);
            }
            finally
            {
                if (intPtr != IntPtr.Zero)
                {
                    WININET.InternetCloseHandle(intPtr);
                }
            }
        }