Dim missingFileList As List
missingFileList = getListofMissingFiles
thisFTP.Initialize("thisFTP",FTP_images_address, FTP_images_port, FTP_images_username, FTP_images_password)
' tried using this - actually makes things worse
'Dim no As NativeObject = thisFTP
'no.GetField("server").SetField("persistConnection", True)
downloadNextFile
Sub downloadNextFile
' only continue if we have files left to download
if (missingFileList.size<1) then return
Dim now As Long
Dim ms as Long = 5000
now=DateTime.now
Do Until (DateTime.now>now+ms)
' dont' do anything
'Log("waiting")
Loop
Log ("sleep ended at "&DateTime.now)
Dim thisFile As Map
thisFile=missingFileList.Get(0)
If File.Exists(directoryPath, "") = False Then File.MakeDir(File.DirDocuments,thisFile.Get("directory"))
Log("STARTING DOWNLOAD OF FILE "&thisFile.Get("filename"))
thisFTP.downloadFile("./"&thisFile.Get("directory")&"/"&thisFile.Get("filename"),False,File.DirDocuments&"/"&thisFile.Get("directory"),thisFile.Get("filename"))
End Sub
Sub thisFTP_DownloadCompleted (ServerPath As String, Success As Boolean)
' remove the first element from the missingFileList, as this is the file we've removed
missingFileList.RemoveAt(0)
downloadNextFile
End Sub