Function amdDownloadStart()
Dim WFD As WIN32_FIND_DATA
Dim sPath As String
Dim hFind As Long
Dim sFileSize As String
Dim tmp As String
Dim isTesting As String
Dim Temp() As String
Dim FileName As String
Dim sOrgPath As String
Dim hFindConnect As Long
Dim itmX As ListItem
Dim rSelect As New Recordset
StatusBar.Panels(1).Text = "Connected"
DoEvents
If chkTesting Then
isTesting = " And type = 'ALL'"
Else
isTesting = " And Not (type = 'ALL' Or type='JL')"
End If
With rSelect
.Open "Select * From tblScanusers Where Not TracksID = 0" & isTesting, myApp.MyCn, adOpenForwardOnly, adLockReadOnly
Do While Not .EOF
StatusBar.Panels(1).Text = "Connected. Checking: " & !UserName
DownloadFiles !TracksID, !UserName, "new"
DoEvents
DownloadFiles !TracksID, !UserName, "corrected"
DoEvents
.MoveNext
Loop
.Close
End With
StatusBar.Panels(1).Text = "Done"
DoEvents
'close the internet connection
InternetCloseHandle hConnection
InternetCloseHandle hOpen
StatusBar.Panels(1).Text = "Disconnected. T-5"
DoEvents
End Function
Function DownloadFiles(CustomerID As Long, UserName As String, Path As String)
Dim WFD As WIN32_FIND_DATA
Dim sPath As String
Dim hFind As Long
Dim sFileSize As String
Dim tmp As String
Dim Temp() As String
Dim FileName As String
Dim sOrgPath As String, hConnection As Long, hOpen As Long, hFindConnect As Long
Dim itmX As ListItem
Dim rSelect As New Recordset
Dim fileget As String
Dim LocalName As String, LocalDirectory As String
Dim fFlag As Boolean
fFlag = False
LocalName = localUserName
'open an internet connection
hOpen = InternetOpen("Download", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
'connect to the FTP server
hConnection = InternetConnect(hOpen, FTPSite, INTERNET_DEFAULT_FTP_PORT, Username, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
hFindConnect = InternetConnect(hOpen, FTPSite, INTERNET_DEFAULT_FTP_PORT, Username, Password, INTERNET_SERVICE_FTP, INTERNET_FLAG_EXISTING_CONNECT Or INTERNET_FLAG_PASSIVE, &H0)
'create a buffer to store the original directory
sOrgPath = String(MAX_PATH, 0)
'get the directory
FtpGetCurrentDirectory hConnection, sOrgPath, Len(sOrgPath)
LocalDirectory = "C:\Documents and Settings\" & LocalName & "\Desktop\Incoming\" & UserName & "\" & Path & "\"
'set connection for getting the file names
If hFindConnect Then
sPath = "public/dealers/" & UserName & "/" & Path & "/" '"/public/dealers/andyd273/new"
FtpSetCurrentDirectory hConnection, "public/dealers/" & UserName & "/" & Path & "/"
DoEvents
hFind = FtpFindFirstFile(hFindConnect, sPath, WFD, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_CACHE_WRITE, 0&)
If hFind Then
Do
tmp = StripNull(WFD.cFileName)
DoEvents
If Len(tmp) Then
If WFD.dwFileAttributes And Not vbDirectory Then
If Not DirExists(LocalDirectory) Then '
NewDirectory LocalDirectory
End If
DoEvents
fileget = ""
Do
StatusBar.Panels(1).Text = "Downloading File " & tmp
DoEvents
fileget = FtpGetFile(hConnection, tmp, LocalDirectory & tmp, True, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0)
DoEvents
Loop While fileget = ""
If fileget = "True" Then
DoEvents
amdSaveFile CustomerID, LocalDirectory & tmp, Path, False
ListView1.ListItems.Add , LocalDirectory & tmp, LocalDirectory & tmp
DoEvents
FtpDeleteFile hConnection, tmp
StatusBar.Panels(1).Text = "Download Finished"
DoEvents
Else
StatusBar.Panels(1).Text = "Download Failed"
MsgBox "Download Failed: " & LocalDirectory & tmp
End If
End If
End If
DoEvents
Loop While InternetFindNextFile(hFind, WFD)
End If
End If
InternetCloseHandle hFind
InternetCloseHandle hFindConnect
InternetCloseHandle hConnection
InternetCloseHandle hOpen
hFindConnect = 0
hFind = 0
End Function