Argh det var dog den dummeste fejl jeg længe har lavet!
Dim boolSyncFTP = SyncLocalFolderFromFTP(strLocalFilePath, strUsername, strPassword, strLocalFilePath)
skulle have været:
Dim boolSyncFTP = SyncLocalFolderFromFTP(strRemoteFilePath, strUsername, strPassword, strLocalFilePath)
Dvs således:
Private Shared Function SyncLocalFolderFromFTP(ByVal strUri As String, ByVal strUsername As String, ByVal strPassword As String, ByVal LocalPath As String)
Dim ftpclientRequest As FtpWebRequest = TryCast(WebRequest.Create(strUri), FtpWebRequest)
If Len(strUsername) > 1 And Len(strPassword) > 1 Then ftpclientRequest.Credentials = New NetworkCredential(strUsername, strPassword)
ftpclientRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
ftpclientRequest.Proxy = Nothing
Dim response As FtpWebResponse = TryCast(ftpclientRequest.GetResponse(), FtpWebResponse)
Dim sr As New StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)
Dim Datastring As String = sr.ReadToEnd()
response.Close()
Dim list As FileStruct() = (New FTPfeatures()).GetList(Datastring)
Dim strRemoteFilePath, strRemoteTimestamp, strLocalFilePath As String
For Each thisstruct As FileStruct In list
If thisstruct.IsDirectory Then
strRemoteTimestamp = thisstruct.CreateTime
strRemoteFilePath = strUri & "/" & thisstruct.Name
strLocalFilePath = LocalPath & "\" & thisstruct.Name
If CreateLocalFolder(strLocalFilePath, strRemoteTimestamp) = True Then
'Kopier mapper rekursivt: nu er mappen oprettet, kald så SyncLocalFolderFromFTP igen, for at kopiere filer og undermapper i den nye mappe.
Dim boolSyncFTP As Boolean = SyncLocalFolderFromFTP(strRemoteFilePath, strUsername, strPassword, strLocalFilePath)
End If
Else
strRemoteTimestamp = thisstruct.CreateTime
strRemoteFilePath = strUri & "/" & thisstruct.Name
strLocalFilePath = LocalPath & "\" & thisstruct.Name
Dim tmp As Boolean = DownloadFTPfile(strRemoteFilePath, strRemoteTimestamp, strLocalFilePath)
End If
Next
Return True
End Function