Question : FTP in VB6 using FtpGetFile API is not saving the file

We have a simple FTP transfer operation that uses the API FtpGetFile to download files to a local folder.  We have been using this in a VFP program successfully for several years, and I've attempted to duplicate that function in a VB6 app.

The FtpGetFile function is returning successful, but there is no file there.  The modified date on that local folder gets updated to the current time, however, so it is almost like it creates the file but cannot save it.  I have paused the code on the next line after the download completes, and the local folder is empty but with a new time stamp.  And file and path names are correct.

We also delete the file from the FTP server after we download, and that is working fine.  Similar logic was working fine in VFP, so the general sequence looks correct to me, and the file attributes are the same.  I've tried it on several workstations, and it does not appear to be related to firewalls or permissions, and it doesn't matter if there is one file or several.

Any ideas how it could get as far as updating the modified date on the local directory but fail to put the file there?

One last note, I read somewhere that the Win FTP api's were only intended to work with Windows FTP servers, and we are using a Linux server, but it worked in VFP so I'm assuming that is not the issue.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
''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)

Answer : FTP in VB6 using FtpGetFile API is not saving the file

I'm not making any progress on this, so I'm just going to stick with the old program.  

Since there is no conclusion on this, should this question be deleted, or should I just accept my own answer as the solution?
Random Solutions  
 
programming4us programming4us