title: Error uploading file to FTP Server
body: <p>I'm trying to use FTP to upload a file to an FTP server. I found the following script online, but I can't get it to work.</p>
  
  <pre><code>$UserName = 'username'
  
  $Password = 'password'
  
  $LocalFilePath = 'c:\FolderName\x.txt'
  
  $RemoteFileName = 'x.txt'
  
  $ServerName = 'my.ftpserver.co.uk'
  
  
  $webclient = New-Object System.Net.WebClient
  
  $webclient.Credentials = New-Object System.Net.NetworkCredential($UserName, $Password)
  
  #Connect to FTP
  $uri = New-Object System.Uri(“ftp://$ServerName/$RemoteFileName”)
  write-host $uri
  
  #upload as file
  $webclient.UploadFile($uri, $LocalFilePath)
  </code></pre>
  
  <p>But when I run this I get the following error:    </p>
  
  <pre><code>    Exception calling "UploadFile" with "2" argument(s): "An exception occurred during a WebClient request."
      At line:21 char:22
  + $webclient.UploadFile &lt;&lt;&lt;&lt; ($uri, $LocalFilePath)
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : DotNetMethodException
  </code></pre>
  
  <p>Can anyone point me in the right direction? 
  I can connect using Filezilla etc from my PC, so it's not blocked by the firewall or anything,</p>