Multiple file download from password protected site

Could anyone help me to develop a script that downloads multiple files from a password protected https site, please?

I could download a single file at a time using the following script, but could not retrieve a list of all the files in the target folder and loop it.

DL target URL

$target_url = “***”

Save to

$file_path = “*”

credential account

$user = “"
$pass = "

WebClient setting

$web_client = New-Object System.Net.WebClient
$credential = New-Object System.Net.NetworkCredential($user, $pass)
$web_client.Credentials = $credential

File download

$web_client.DownloadFile($target_url, $file_path)

If you know the file names that you need to grab you could add them to an array and go over them with a foreach:

$target_urls = @("***","***") 

Foreach ($target_url in $target_urls) {
# File download
$web_client.DownloadFile($target_url, $file_path)
}

If you don’t know the names in advance you may need to use another method to get those. If Directory Index is enabled on the site this Stack Overflow answer might point you in the right direction: Can Powershell be used to list the contents of a URL directory?

Thank you, Klaage!

It worked.