Downloading a file via FTP in code

J

Jeff Standen

Hi all,

I'd like to download a file to a specified directory in code, without
resorting to what I currently do, which is writing a text file, saving it
and using Shell() to call the Windows FTP program. Is there a simpler way to
do this?

Cheers,

Jeff
Using Win XPPro & Office 2003
 
R

Robin Hammond

Jeff,

there's an API call I use a lot. It should work with an FTP site.

'API file download call
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal strURL As String, _
ByVal strFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Public Sub GetInternetFile(strFileName As String, strTargetFolder As String)
Dim lReturn As Long
Dim strFullURL As String
Dim strLocation As String

strFullURL = "http://100.100.100.100/" & strFileName
strLocation = strTargetFolder & strFileName

On Error Resume Next
SetAttr strLocation, vbNormal
On Error GoTo 0

lReturn = URLDownloadToFile(0, strFullURL, strLocation, 0, 0)
If lReturn <> 0 Then msgbox "download failed"
End Sub

Robin Hammond
www.enhanceddatasystems.com
 
J

Jeff Standen

Fantastic - thank you :)

Jeff

Robin Hammond said:
Jeff,

there's an API call I use a lot. It should work with an FTP site.

'API file download call
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal strURL As String, _
ByVal strFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Public Sub GetInternetFile(strFileName As String, strTargetFolder As String)
Dim lReturn As Long
Dim strFullURL As String
Dim strLocation As String

strFullURL = "http://100.100.100.100/" & strFileName
strLocation = strTargetFolder & strFileName

On Error Resume Next
SetAttr strLocation, vbNormal
On Error GoTo 0

lReturn = URLDownloadToFile(0, strFullURL, strLocation, 0, 0)
If lReturn <> 0 Then msgbox "download failed"
End Sub

Robin Hammond
www.enhanceddatasystems.com

way
 
Top