what VB code will go out to a website and download a file?

I have a website with an .exe file at a certain location.
What VB6 code will go to that site, and download the .exe to the
CURRENT WORKING DIRECTORY and then tell me its done?
rbendAsked:
Who is Participating?
 
nffvrxqgrcfqvvcConnect With a Mentor Commented:
Copy paste the following into Form_Declerations...
'You can also add all the code in Form_Load to a command button instead.

'--CODE BEGINS---
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function


Private Sub Form_Load()
Dim Ssave As String
'Save file as?
Ssave = "c:\savefilename.exe"
'URL location of file?
DownloadFile "http://www.somesite.com/files/filename.exe", Ssave
DoEvents
'Display message when its finished downloading
MsgBox "The file has been downloaded - and saved as:  " & Ssave, vbInformation, "Finished"
End Sub

'---CODE ENDS---

Make sure the site you are pulling the .exe file from allows you directly download from the sites folder rather than having to click a link to be able to download it.
0
 
rbendAuthor Commented:
yes this works for me:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.