title: PowerShell FTPS upload fails with "System error."
body: <h1>The problem:</h1>
  
  <p>A client requires that we upload extracted data from our system to their box.com platform, rather than our normal SFTP utility. I have box.com credentials, and am aware they require FTPS not SFTP, and require passive mode. I've cribbed a fragment from <a href="http://www.thomasmaurer.ch/2010/11/powershell-ftp-upload-and-download/" rel="nofollow noreferrer">ThomasMaurer's Powershell FTP Upload and Download script</a>. Powershell version on my server is 4.0</p>
  
  <h1>Code fragment is:</h1>
  
  <pre><code>#config 
  $Username = "username@host.com"
  $Password = "redactedpassword"
  $LocalFile = "C:\path\to\my\file.csv"
  $RemoteFile = "ftp://ftp.box.com:990/file.csv"
  #Create FTPWebRequest
  $FTPRequest = [System.Net.FtpWebRequest]::Create($RemoteFile)
  $FTPRequest = [System.Net.FtpWebRequest]$FTPRequest
  $FTPRequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
  $FTPRequest.Credentials = New-Object System.Net.NetworkCredential($Username, $Password)
  $FTPRequest.UseBinary = $true
  $FTPRequest.UsePassive = $true
  #read file for upload
  $FileContent = gc -en byte $LocalFile
  $FTPRequest.ContentLength = $FileContent.Length
  #get stream request by bytes
  $run = $FTPRequest.GetRequestStream()
  $run.Write($FileContent,0,$FileContent.Length)
  #cleanup
  $run.Close()
  $run.Dispose()
  </code></pre>
  
  <h1>The error(s):</h1>
  
  <pre class="lang-none prettyprint-override"><code>Exception calling "GetRequestStream" with "0" argument(s): "System error." At C:\path\to\my\powershellscript.ps1:28 char:1
  + $Run = $FTPRequest.GetRequestStream()
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo : NotSpecified: () [], MethodInvocationException
  + FullyQualifiedErrorId: WebException
  </code></pre>
  
  <p>I also get downstream errors on calling the <code>$FileContent.Length</code> property and <code>$run.close</code> and <code>$run.dispose()</code>.</p>
  
  <p>Has anyone successfully automated to box (specifically) or to a passive implicit-ssl using only PowerShell 4.0 commands, and do you have a solid pattern I could reuse?   Many thanks</p>