ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Downloading a file via FTP in code (https://www.excelbanter.com/excel-programming/296713-downloading-file-via-ftp-code.html)

Jeff Standen

Downloading a file via FTP in code
 
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



Robin Hammond[_2_]

Downloading a file via FTP in code
 
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

"Jeff Standen" wrote in message
...
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 Standen

Downloading a file via FTP in code
 
Fantastic - thank you :)

Jeff

"Robin Hammond" wrote in message
...
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

"Jeff Standen" wrote in message
...
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








All times are GMT +1. The time now is 07:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com