FluentFTP
FluentFTP copied to clipboard
Duplicate directories with FtpFolderSyncMode.Update
Hi. I just want to report what I believe to be a bug inside fluentFtp. When downloading and uploading a directory (as there is not a duplicate folder method at the moment) there is a loss of files. I am downloading and uploading a folder with 230 files and directories and after many tests i saw that I was duplicating a folder with less files.
To resolve this, you need to download and upload a number of times with FtpFolderSyncMode.Update until you don't get the right number of files. This is the code I used to resolve the issue. I hope it can help.
Public Shared Sub DuplicateDirectoryFTP(ftpClient As FtpClient, remoteDirToBeDuplicatedPath As String, localDuplicatedDirPath As String, remoteDuplicatedDirPath As String)
Dim remoteTotalOfFilesDirToDuplicate As Integer = 0
Dim numOfLocalFiles As Integer = 0
Dim numOfLocalDirs As Integer = 0
Dim localTotalDuplicatedDir As Integer = 0
Dim remoteTotalOfFilesDuplicatedDir As Integer = 0
Try
Do
remoteTotalOfFilesDirToDuplicate = ftpClient.GetListing(remoteDirToBeDuplicatedPath, FtpListOption.Recursive).Length
ftpClient.DownloadDirectory(localDuplicatedDirPath, remoteDirToBeDuplicatedPath, FtpFolderSyncMode.Update)
numOfLocalDirs = My.Computer.FileSystem.GetDirectories(localDuplicatedDirPath, FileIO.SearchOption.SearchAllSubDirectories).Count
numOfLocalFiles = My.Computer.FileSystem.GetFiles(localDuplicatedDirPath, FileIO.SearchOption.SearchAllSubDirectories).Count
localTotalDuplicatedDir = numOfLocalDirs + numOfLocalFiles
Loop Until localTotalDuplicatedDir = remoteTotalOfFilesDirToDuplicate
Do
ftpClient.UploadDirectory(localDuplicatedDirPath, remoteDuplicatedDirPath, FtpFolderSyncMode.Update)
remoteTotalOfFilesDuplicatedDir = ftpClient.GetListing(remoteDuplicatedDirPath, FtpListOption.Recursive).Length
Loop Until localTotalDuplicatedDir = remoteTotalOfFilesDuplicatedDir
My.Computer.FileSystem.DeleteDirectory(localDuplicatedDirPath, FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin, FileIO.UICancelOption.ThrowException)
Catch ex As Exception
Throw ex
End Try
End Sub`
-- https://github.com/christiandiguida