public FtpDirectoryInfo[] GetDirectories(String path) { WIN32_FIND_DATA findData = new WIN32_FIND_DATA(); IntPtr findFile = WinINet.FtpFindFirstFile(m_hConnect, path, ref findData, WinINet.INTERNET_FLAG_NO_CACHE_WRITE, IntPtr.Zero); try { List <FtpDirectoryInfo> directories = new List <FtpDirectoryInfo>(); if (findFile == IntPtr.Zero) { if (Marshal.GetLastWin32Error() == WinApi.ERROR_NO_MORE_FILES) { return(directories.ToArray()); } else { return(directories.ToArray()); } } if ((findData.dfFileAttributes & WinApi.FILE_ATTRIBUTE_DIRECTORY) == WinApi.FILE_ATTRIBUTE_DIRECTORY) { FtpDirectoryInfo directoryInfo = new FtpDirectoryInfo(this, new String(findData.fileName).TrimEnd('\0')); directoryInfo.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); directoryInfo.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); directoryInfo.CreationTime = findData.ftCreationTime.ToDateTime(); directoryInfo.Attributes = (FileAttributes)findData.dfFileAttributes; directories.Add(directoryInfo); } findData = new WIN32_FIND_DATA(); while (WinINet.InternetFindNextFile(findFile, ref findData) != 0) { if ((findData.dfFileAttributes & WinApi.FILE_ATTRIBUTE_DIRECTORY) == WinApi.FILE_ATTRIBUTE_DIRECTORY) { FtpDirectoryInfo directoryInfo = new FtpDirectoryInfo(this, new String(findData.fileName).TrimEnd('\0')); directoryInfo.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); directoryInfo.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); directoryInfo.CreationTime = findData.ftCreationTime.ToDateTime(); directoryInfo.Attributes = (FileAttributes)findData.dfFileAttributes; directories.Add(directoryInfo); } findData = new WIN32_FIND_DATA(); } if (Marshal.GetLastWin32Error() != WinApi.ERROR_NO_MORE_FILES) { } return(directories.ToArray()); } finally { if (findFile != IntPtr.Zero) { WinINet.InternetCloseHandle(findFile); } } }
private List <String> List(String mask, Boolean onlyDirectories) { WIN32_FIND_DATA findData = new WIN32_FIND_DATA(); IntPtr findFile = WinINet.FtpFindFirstFile(m_hConnect, mask, ref findData, WinINet.INTERNET_FLAG_NO_CACHE_WRITE, IntPtr.Zero); try { List <String> files = new List <String>(); if (findFile == IntPtr.Zero) { if (Marshal.GetLastWin32Error() == WinApi.ERROR_NO_MORE_FILES) { return(files); } else { 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 WIN32_FIND_DATA(); while (WinINet.InternetFindNextFile(findFile, 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 WIN32_FIND_DATA(); } if (Marshal.GetLastWin32Error() != WinApi.ERROR_NO_MORE_FILES) { } return(files); } finally { if (findFile != IntPtr.Zero) { WinINet.InternetCloseHandle(findFile); } } }
public Boolean DirectoryExists(String path) { WIN32_FIND_DATA findData = new WIN32_FIND_DATA(); IntPtr findFile = WinINet.FtpFindFirstFile(m_hConnect, path, ref findData, WinINet.INTERNET_FLAG_NO_CACHE_WRITE, IntPtr.Zero); try { if (findFile == IntPtr.Zero) { return(false); } return(true); } finally { if (findFile != IntPtr.Zero) { WinINet.InternetCloseHandle(findFile); } } }