-
Jul 11th, 2018, 12:08 PM
#1
Thread Starter
Member
[RESOLVED] Download Image from URL that requires Authentication
Hi,
I need help on downloading images from a URL (that requires username and password) to a directory on my local system.
I have used the following codes :
Private Sub cmdDownload_Click()
Dim sDestPath As String
Dim sFileName As String
Dim sTmp As String
Dim bResult As Boolean
sFileName = Mid$(txtURL.Text, InStrRev(txtURL.Text, "/") + 1)
sDestPath = Trim$(txtDestPath.Text)
If sDestPath = vbNullString Then
sDestPath = App.Path
End If
If Right(sDestPath, 1) <> "\" Then
sDestPath = sDestPath & "\"
End If
sDestPath = sDestPath & sFileName
bResult = DownloadFile(txtURL.Text, sDestPath)
If bResult Then
lblResult.Caption = "File downloaded."
Else
lblResult.Caption = "Error on download file."
Exit Sub
End If
If chkViewFile.Value = vbChecked Then
ShellExecute Me.hwnd, "open", sDestPath, vbNullString, vbNullString, 1
End If
End Sub
'This is a bas module
Option Explicit
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
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(sURLFile As String, sLocalFilename As String) As Boolean
Dim lRetVal As Long
lRetVal = URLDownloadToFile(0, sURLFile, sLocalFilename, 0, 0)
If lRetVal = 0 Then DownloadFile = True
End Function
But i cant get it done, because the URL requires a username and password, but i dont know how to enter the username and password. I have the username and password, but dont know how to go about using it and make the code work.
Please help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|