FTP Download (1 Viewer)

mtn

Registered User.
Local time
Today, 18:48
Joined
Jun 8, 2009
Messages
54
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
 

RuralGuy

AWF VIP
Local time
Today, 11:48
Joined
Jul 2, 2005
Messages
13,826
When you invoke the Function, to what do you set the sDir argument?
 

mtn

Registered User.
Local time
Today, 18:48
Joined
Jun 8, 2009
Messages
54
Thanks for offering to help.

This is the function I used in calling it:

Public Function FTPDownload(txtFileToDownload As String, txtDownloadFileName As String)

FTPDownFile ELookup("ftpHostName", "tblSMTP"), _
ELookup("ftpUserName", "tblSMTP"), _
ELookup("ftpPassword", "tblSMTP"), _
txtFileToDownload, _
txtDownloadFileName, _
ELookup("ftpDirectory", "tblSMTP"), _
ELookup("ftpMode", "tblSMTP")
End Function

The sDir argument is the remote folder on my website where I want to download the file from. The only parameter I pass is the remote file name and the name I want to save it with on my computer.
 

RuralGuy

AWF VIP
Local time
Today, 11:48
Joined
Jul 2, 2005
Messages
13,826
So what happens if you specify the full path for the txtDownloadFileName that includes the location you want starting with the drive?
 

shadow9449

Registered User.
Local time
Today, 13:48
Joined
Mar 5, 2004
Messages
1,037
I had this problem when I started using wget to download files from the internet in my applications. (You may consider this option as it might be easier to work with then the FTP function). I think that it downloads into the default directory.

The way I get around this is by using Application.SetOption "Default Database directory" to set the directory to where I want it to be and then do the transfer and it works fine.

SHADOW
 

Users who are viewing this thread

Top Bottom