Multiple file download from password protected site

Welcome Forums General PowerShell Q&A Multiple file download from password protected site

Viewing 2 reply threads
  • Author
    Posts
    • #245796
      Participant
      Topics: 1
      Replies: 1
      Points: -6
      Rank: Member

      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)

    • #245946
      Participant
      Topics: 12
      Replies: 38
      Points: 281
      Helping Hand
      Rank: Contributor

      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:

      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?

    • #246114
      Participant
      Topics: 1
      Replies: 1
      Points: -6
      Rank: Member

      Thank you, Klaage!

      It worked.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.