/// <summary> /// makes any changes done while the app was not running to the remote folder /// For 'local to remote' mode /// </summary> /// <param name="rPath">path to remote ftpbox</param> /// <param name="path">path to file to be checked</param> /// <param name="lPath">local path to ftpbox</param> private void First_Check_LtR(string rPath, string path, string lPath) { FileAttributes attr = System.IO.File.GetAttributes(path); FileInfo fi = new FileInfo(path); string loc; // = fi.Name; loc = path.Replace(lPath, ""); loc = loc.Replace(fi.Name, ""); loc = loc.Replace(@"\", @"/"); loc = noSlashes(rPath) + @"/" + noSlashes(loc); ftp.SetCurrentDirectory(loc); if ((attr & FileAttributes.Directory) != FileAttributes.Directory) { string rDir = path.Replace(lPath, ""); //remove the path to ftpBox from the path rDir = "/" + noSlashes(loc) + "/" + rDir; rDir = rDir.Replace(@"\", @"/"); string name = fi.Name; rDir = rDir.Replace(name, ""); ftp.SetCurrentDirectory(rDir); if (ftp.FileExists(fi.Name)) { //string rDir = path.Replace(lPath, ""); //remove the path to ftpBox from the path //string name = fi.Name; //get the name of the file //rDir = rDir.Replace(name, ""); //remove the name from the path //rDir = rDir.Replace(@"\", @"/"); //replace \ with / //rDir = rPath + "/" + noSlashes(rDir); //get the full path to the new remote directory where the new file will be created ftp.SetCurrentDirectory(rDir); FtpFileInfo ftpfi = new FtpFileInfo(ftp, name); ftpfi.Attributes.GetHashCode(); int rHash = ftpfi.GetHashCode(); int lHash = fi.GetHashCode(); if (rHash == lHash && ftpfi.LastWriteTime != fi.LastWriteTime) { ftp.RemoveFile(name); ftp.PutFile(path, name); if (ShowNots()) { tray.ShowBalloonTip(100, "FTPbox", string.Format("File {0} was successfully updated.", name), ToolTipIcon.Info); } } } else { //string name = fi.Name; //get the name of the file /* rDir = rDir.Replace(name, ""); //remove the name from the path rDir = rDir.Replace(@"\", @"/"); //replace \ with / rDir = rPath + "/" + noSlashes(rDir); //get the full path to the new remote directory where the new file will be created */ ftp.PutFile(path, name); if (ShowNots()) { tray.ShowBalloonTip(100, "FTPbox", string.Format("File {0} was successfully uploaded.", name), ToolTipIcon.Info); } } } else if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { string rDir = path.Replace(lPath, ""); //remove the path to ftpBox from the path string name = fi.Name; //get the name of the file rDir = "/" + noSlashes(loc) + "/" + rDir; ftp.SetCurrentDirectory(rDir); if (!ftp.DirectoryExists(name)) { /* rDir = rDir.Replace(name, ""); //remove the name from the path rDir = rDir.Replace(@"\", @"/"); //replace \ with / rDir = rPath + "/" + noSlashes(rDir); //get the full path to the new remote directory where the new file will be created */ ftp.CreateDirectory(name); if (ShowNots()) { tray.ShowBalloonTip(100, "FTPbox", string.Format("Folder {0} was successfully created.", name), ToolTipIcon.Info); } } } }
/// <summary> /// Gets details of all files and their available FTP file information from the current working FTP directory that match the file mask. /// </summary> /// <param name="mask">A <see cref="String"/> representing the file mask to match files.</param> /// <returns>A <see cref="FtpFileInfo[]"/> representing the files in the current working directory.</returns> public FtpFileInfo[] GetFiles(string mask) { 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<FtpFileInfo> files = new List<FtpFileInfo>(); if (hFindFile == IntPtr.Zero) { if (Marshal.GetLastWin32Error() == WINAPI.ERROR_NO_MORE_FILES) { return files.ToArray(); } else { Error(); return files.ToArray(); } } if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) != WINAPI.FILE_ATTRIBUTE_DIRECTORY) { FtpFileInfo file = new FtpFileInfo(this, new string(findData.fileName).TrimEnd('\0')); file.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); file.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); file.CreationTime = findData.ftCreationTime.ToDateTime(); file.Attributes = (FileAttributes)findData.dfFileAttributes; files.Add(file); } findData = new WINAPI.WIN32_FIND_DATA(); while (WININET.InternetFindNextFile(hFindFile, ref findData) != 0) { if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) != WINAPI.FILE_ATTRIBUTE_DIRECTORY) { FtpFileInfo file = new FtpFileInfo(this, new string(findData.fileName).TrimEnd('\0')); file.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); file.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); file.CreationTime = findData.ftCreationTime.ToDateTime(); file.Attributes = (FileAttributes)findData.dfFileAttributes; files.Add(file); } findData = new WINAPI.WIN32_FIND_DATA(); } if (Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES) Error(); return files.ToArray(); } finally { if (hFindFile != IntPtr.Zero) WININET.InternetCloseHandle(hFindFile); } }
/// <summary> /// Gets details of all files and their available FTP file information from the current working FTP directory that match the file mask. /// </summary> /// <param name="mask">A <see cref="String"/> representing the file mask to match files.</param> /// <returns>A <see cref="FtpFileInfo[]"/> representing the files in the current working directory.</returns> public FtpFileInfo[] GetFiles(string mask) { 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 <FtpFileInfo> files = new List <FtpFileInfo>(); if (hFindFile == IntPtr.Zero) { if (Marshal.GetLastWin32Error() == WINAPI.ERROR_NO_MORE_FILES) { return(files.ToArray()); } else { Error(); return(files.ToArray()); } } if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) != WINAPI.FILE_ATTRIBUTE_DIRECTORY) { FtpFileInfo file = new FtpFileInfo(this, new string(findData.fileName).TrimEnd('\0')); file.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); file.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); file.CreationTime = findData.ftCreationTime.ToDateTime(); file.Attributes = (FileAttributes)findData.dfFileAttributes; files.Add(file); } findData = new WINAPI.WIN32_FIND_DATA(); while (WININET.InternetFindNextFile(hFindFile, ref findData) != 0) { if ((findData.dfFileAttributes & WINAPI.FILE_ATTRIBUTE_DIRECTORY) != WINAPI.FILE_ATTRIBUTE_DIRECTORY) { FtpFileInfo file = new FtpFileInfo(this, new string(findData.fileName).TrimEnd('\0')); file.LastAccessTime = findData.ftLastAccessTime.ToDateTime(); file.LastWriteTime = findData.ftLastWriteTime.ToDateTime(); file.CreationTime = findData.ftCreationTime.ToDateTime(); file.Attributes = (FileAttributes)findData.dfFileAttributes; files.Add(file); } findData = new WINAPI.WIN32_FIND_DATA(); } if (Marshal.GetLastWin32Error() != WINAPI.ERROR_NO_MORE_FILES) { Error(); } return(files.ToArray()); } finally { if (hFindFile != IntPtr.Zero) { WININET.InternetCloseHandle(hFindFile); } } }