I have the FtpGetFile function working on an XP System with no problems. However, I wish to use this code for a client that will be running Windows 2000 Professional. I did a little looking around and found that this OS is under the requirements for operating systems (http://msdn.microsoft.com/en-us/library/aa384157(VS.85).aspx).
I am running Windows 2000 on a virtual server. I am looking for a specific file name. The function brings it down correctly the first time. I delete it from the remote location. I drop another file of the same name, but different size and content. When the function is called a second time, it downloads the same file as the first attempt, even though that file was deleted and no longer a possibility of being downloaded. This happens over and over until I restart the application and then whatever file I get with FtpGetFile the first time mimics the same odd behavior as I mentioned above. Does anyone know how to switch off any cacheing (if that is the case) to get this to work?
Keep in mind I have run this same software application on another Win XP system and a Win 2003 (virtual server) system using the same FTP source with no problems. This odd behavior only occurs on the Windows 2000 OS. I am not able to use the actual server at the client, which is why I am using a virtual server image for testing.
My (relevant) code is below:
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal HINet As Integer) As Integer
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Integer, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Integer) As Integer
Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Integer, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Integer, ByVal lFlags As Integer, ByVal lContext As Integer) As Integer
Private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (ByVal hFtpSession As Integer, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal dwFlagsAndAttributes As Integer, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Integer, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Integer, ByVal dwContext As Integer) As Boolean
Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (ByVal hFtpSession As Integer, ByVal lpszFileName As String) As Boolean
Dim FTPServiceAlias As String = configurationAppSettings.GetValue("FTPServiceAlias ", GetType(System.String)).ToString
Dim FTPServerName As String = configurationAppSettings.GetValue("FTPServerName", GetType(System.String)).ToString
Dim FTPPortNumber As Integer = CInt(configurationAppSettings.GetValue("FTPPortNum ber", GetType(System.String)))
Dim FTPAccessType As Integer = CInt(configurationAppSettings.GetValue("FTPAccessT ype", GetType(System.String)))
Dim FTPUserName As String = configurationAppSettings.GetValue("FTPUserName", GetType(System.String)).ToString
Dim FTPUserPassword As String = configurationAppSettings.GetValue("FTPUserPassword ", GetType(System.String)).ToString
Dim FTPFolder As String = configurationAppSettings.GetValue("FTPFolder", GetType(System.String)).ToString
Private Sub GetFileByFTP()
Try
Dim INet, INetConn As Integer
Dim RC As Boolean
INet = InternetOpen(FTPServiceAlias, FTPAccessType, vbNullString, vbNullString, 0)
If Err.LastDllError <> 0 Then
LocalWriteToErrorFile(" FTP InternetOpen Error: " & Err.LastDllError.ToString & ". See http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx for details.")
End If
INetConn = InternetConnect(INet, FTPServerName, FTPPortNumber, FTPUserName, FTPUserPassword, 1, 0, 0)
If Err.LastDllError <> 0 Then
LocalWriteToErrorFile(" FTP InternetConnect Error: " & Err.LastDllError.ToString & ". See http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx for details.")
End If
RC = FtpGetFile(INetConn, ScheduleFile, InputFilePath & "\" & ScheduleFile, True, 1, 0, 0)
If RC = False And Err.LastDllError <> 80 Then
LocalWriteToErrorFile(" FTP Get Error: " & Err.LastDllError.ToString & ". See http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx for details.")
End If
If CInt(Err.LastDllError) = 0 Then
Dim timeOut As DateTime = Now.AddMilliseconds(8000)
RC = FtpDeleteFile(INetConn, ScheduleFile)
If RC = False And Err.LastDllError <> 0 Then
LocalWriteToErrorFile(" FTP Delete Error: " & Err.LastDllError.ToString & ". See http://msdn.microsoft.com/en-us/library/ms681381(VS.85).aspx for details.")
End If
End If
InternetCloseHandle(INetConn)
InternetCloseHandle(INet)
Catch ex As Exception
LocalWriteToErrorFile(ex.ToString())
End Try
End Sub
|