An exception occurred during a WebClient request.

Welcome Forums General PowerShell Q&A An exception occurred during a WebClient request.

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 11 months ago.

  • Author
  • #66850

    Points: 0
    Rank: Member


    I am a newbie and facing following error while uploading XML files via FTP. Please advise what's being wrong here.

    Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
    At line:17 char:5
    + $webclient.UploadFile($Uri, $item.FullName)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

    #Files to upload
    $Backup = "D:\...\xmls\backup_of_errors\"

    #ftp server
    $ftp = "s"
    $user = "Username"
    $pass = Read-Host 'Password' -AsSecureString

    $webclient = New-Object System.Net.WebClient

    $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)

    foreach($item in (dir $Dir "*.xml")){
    "Uploading $item..."
    $uri = New-Object System.Uri($ftp+$item.Name)
    $webclient.UploadFile($Uri, $item.FullName)

  • #66864

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    I don't think the WebClient class handles anything other than HTTP or HTTPS. You'd need an FTP client that understood SFTP. They're entirely different protocols.

The topic ‘An exception occurred during a WebClient request.’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort