Her den:
Sub GetFile()
ftpo.Cancel
ftpo.Execute ftpo.URL, "GET " & RemoteFile & " " & LocalFile
Do While ftpo.StillExecuting
DOEObj.Do_events
Loop
ftpo.Cancel
End Sub
dim fso, ftpo, Temp, FileList, TxtFile
url = "ftp://" & &(1:)
usr = &(2:)
pwd = &(3:)
dim DOEObj
set DOEObj = createobject("interrupter.DoEvents")
FileList = ""
&(6:) = ""
set ftpo = CreateObject("InetCtls.Inet.1") 'Msinet.ocx
With ftpo
.Cancel
.AccessType = icUseDefault
.URL = url
.RequestTimeOut = 60
.UserName = usr
.Password = pwd
.Execute , "DIR"
End With
Do While ftpo.StillExecuting
DOEObj.Do_events
Loop
Select Case State
Case icResponseCompleted
Temp = ftpo.GetChunk(1024)
Do While Len(Temp) > 0
FileList = FileList & Temp
Temp = ftpo.GetChunk(1024)
Loop
Case icError
MsgBox "Hent VejReister fra CPR bliver afsluttet pga. følgende fejl: " & vbCrLf & ftpo.icResponseCode & ":" & ftpo.icResponseInfo
End Select
If &(4:) = "Y" Then
set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FileExists (&(5:)) Then
Set TxtFile = fso.CreateTextFile(&(5:))
End If
set TxtFile = fso.OpenTextFile(&(5:),2, True)
End If
FileArray = Split(FileList, vbCrLf)
FileArray = Filter(FileArray, ".")
MsgBox "Fundne filer: " & UBound(FileArray)
For i = LBound(FileArray) To UBound(FileArray)
If Len(FileArray(i)) > 0 Then
FileArray(i) = Right(FileArray(i), 15)
If &(4:) = "Y" Then
TxtFile.WriteLine(FileArray(i))
End If
&(6:) = &(6:) & FileArray(i) & vbCrLf
RemoteFile = FileArray(i)
LocalFile = "c:\Download\VejReg\" & RemoteFile
' MsgBox "File " & i & ": Fra : " & RemoteFile & " Til: " & LocalFile
Call GetFile
End If
Next
If &(4:) = "Y" Then
TxtFile.Close
End If
ftpo.Execute ftpo.URL, "CLOSE"
Set ftpo = Nothing
Set fso = Nothing
set DOEObj = Nothing