Hello and happy new year to everyone.
I have been using this code in my application to download files from my website and it works well except that it downloads the file to my Documents Folder. Is there a way I can change the default location to download file to another location say the applications folder or user desktop?
I got the code form here: http://wiki.lessthandot.com/index.php/FTP_in_Access
Function FTPDownFile(ByVal HostName As String, _
ByVal UserName As String, _
ByVal Password As String, _
ByVal LocalFileName As String, _
ByVal RemoteFileName As String, _
ByVal sDir As String, _
ByVal sMode As String) As Boolean
' Declare variables
Dim hConnection, hOpen ' Used For Handles
Dim fso As Object
'check for file existence, delete if necessary
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(LocalFileName) Then
VBA.Kill LocalFileName
Set fso = Nothing
End If
' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
' Connect to FTP
hConnection = InternetConnect(hOpen, HostName, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
' Change Directory
Call FtpSetCurrentDirectory(hConnection, sDir)
' Set Download Flag to True
FTPDownFile = True
' Download File
If FTPGetFile(hConnection, RemoteFileName, LocalFileName, False, 1, 0, 1) = False Then
FTPDownFile = False
End If
SetAttr LocalFileName, vbNormal + vbArchive
' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)
End Function
I have been using this code in my application to download files from my website and it works well except that it downloads the file to my Documents Folder. Is there a way I can change the default location to download file to another location say the applications folder or user desktop?
I got the code form here: http://wiki.lessthandot.com/index.php/FTP_in_Access
Function FTPDownFile(ByVal HostName As String, _
ByVal UserName As String, _
ByVal Password As String, _
ByVal LocalFileName As String, _
ByVal RemoteFileName As String, _
ByVal sDir As String, _
ByVal sMode As String) As Boolean
' Declare variables
Dim hConnection, hOpen ' Used For Handles
Dim fso As Object
'check for file existence, delete if necessary
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(LocalFileName) Then
VBA.Kill LocalFileName
Set fso = Nothing
End If
' Open Internet Connecion
hOpen = InternetOpen("FTP", 1, "", vbNullString, 0)
' Connect to FTP
hConnection = InternetConnect(hOpen, HostName, INTERNET_DEFAULT_FTP_PORT, UserName, Password, INTERNET_SERVICE_FTP, IIf(PassiveConnection, INTERNET_FLAG_PASSIVE, 0), 0)
' Change Directory
Call FtpSetCurrentDirectory(hConnection, sDir)
' Set Download Flag to True
FTPDownFile = True
' Download File
If FTPGetFile(hConnection, RemoteFileName, LocalFileName, False, 1, 0, 1) = False Then
FTPDownFile = False
End If
SetAttr LocalFileName, vbNormal + vbArchive
' Close Internet Connection
Call InternetCloseHandle(hOpen)
Call InternetCloseHandle(hConnection)
End Function