Downloading a file via FTP in code

  • Thread starter Thread starter Jeff Standen
  • Start date Start date
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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top