''directory of remote folder
pData.cFileName = String(MAX_PATH, 0)
hFind = FtpFindFirstFile(hConn, "inbox", pData, 0, 0)
nLastError = Err.LastDllError
If hFind = 0 Then
If (nLastError = ERROR_NO_MORE_FILES) Then
tsLog.WriteLine "No files to receive"
Else
tsLog.WriteLine "Error: FtpFindFirstFile"
End If
Exit Sub
End If
''for each item in remote folder
Do
''parse file name
strItemName = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
''download
lRes = FtpGetFile(hConn, _
strItemName, dirReceive & "\" & strItemName, _
False, FILE_ATTRIBUTE_NORMAL, _
FTP_TRANSFER_TYPE_BINARY, 0)
''delete remote
If lRes <> 0 Then
tsLog.WriteLine "Error downloading file: " & strItemName
Else
tsLog.WriteLine "Downloaded " & dirReceive & "\" & strItemName
bRet = FtpDeleteFile(hConn, "inbox/" & strItemName)
If Not bRet Then
tsLog.WriteLine "Error deleting remote file: " & strItemName
End If
End If
DoEvents
pData.cFileName = String(MAX_PATH, 0)
bRet = InternetFindNextFile(hFind, pData)
If Not bRet Then
dError = Err.LastDllError
If dError = ERROR_NO_MORE_FILES Then
InternetCloseHandle (hFind)
Exit Do
Else
tsLog.WriteLine "Error: InternetFindNextFile"
InternetCloseHandle (hFind)
Exit Sub
End If
End If
Loop
InternetCloseHandle (hConn)
|